forked from directus/v8-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add extensions and list views endpoints
- Loading branch information
1 parent
9886f36
commit 1c81e1b
Showing
8 changed files
with
155 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Directus\Services; | ||
|
||
abstract class AbstractAddOnsController extends AbstractService | ||
{ | ||
protected $basePath = null; | ||
|
||
protected function all($basePath, array $params = []) | ||
{ | ||
$addOns = []; | ||
|
||
if (!file_exists($basePath)) { | ||
return ['data' => $addOns]; | ||
} | ||
|
||
$filePaths = find_directories($basePath); | ||
foreach ($filePaths as $path) { | ||
$path .= '/meta.json'; | ||
|
||
if (!file_exists($path)) { | ||
continue; | ||
} | ||
|
||
$addOnsPath = trim(substr($path, strlen($basePath)), '/'); | ||
$data = ['id' => basename(dirname($addOnsPath))]; | ||
|
||
$meta = @json_decode(file_get_contents($path), true); | ||
if ($meta) { | ||
unset($meta['id']); | ||
$data = array_merge($data, $meta); | ||
} | ||
|
||
$addOns[] = $data; | ||
} | ||
|
||
return ['data' => $addOns]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Directus\Services; | ||
|
||
use Directus\Application\Container; | ||
|
||
class ExtensionsService extends AbstractAddOnsController | ||
{ | ||
public function __construct(Container $container) | ||
{ | ||
parent::__construct($container); | ||
|
||
$basePath = $this->container->get('path_base'); | ||
$this->basePath = $basePath . '/public/core/extensions'; | ||
} | ||
|
||
public function findAll(array $params = []) | ||
{ | ||
return $this->all($this->basePath, $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Directus\Services; | ||
|
||
use Directus\Application\Container; | ||
|
||
class ListViewsService extends AbstractAddOnsController | ||
{ | ||
public function __construct(Container $container) | ||
{ | ||
parent::__construct($container); | ||
|
||
$basePath = $this->container->get('path_base'); | ||
$this->basePath = $basePath . '/public/core/list_views'; | ||
} | ||
|
||
public function findAll(array $params = []) | ||
{ | ||
return $this->all($this->basePath, $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Directus\Api\Routes; | ||
|
||
use Directus\Application\Application; | ||
use Directus\Application\Http\Request; | ||
use Directus\Application\Http\Response; | ||
use Directus\Application\Route; | ||
use Directus\Services\ExtensionsService; | ||
|
||
class Extensions extends Route | ||
{ | ||
/** | ||
* @param Application $app | ||
*/ | ||
public function __invoke(Application $app) | ||
{ | ||
create_ping_route($app); | ||
|
||
$app->get('', [$this, 'all']); | ||
} | ||
|
||
public function all(Request $request, Response $response) | ||
{ | ||
$service = new ExtensionsService($this->container); | ||
$responseData = $service->findAll(); | ||
|
||
return $this->responseWithData($request, $response, $responseData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Directus\Api\Routes; | ||
|
||
use Directus\Application\Application; | ||
use Directus\Application\Http\Request; | ||
use Directus\Application\Http\Response; | ||
use Directus\Application\Route; | ||
use Directus\Services\ListViewsService; | ||
|
||
class ListViews extends Route | ||
{ | ||
/** | ||
* @param Application $app | ||
*/ | ||
public function __invoke(Application $app) | ||
{ | ||
create_ping_route($app); | ||
|
||
$app->get('', [$this, 'all']); | ||
} | ||
|
||
public function all(Request $request, Response $response) | ||
{ | ||
$service = new ListViewsService($this->container); | ||
$responseData = $service->findAll(); | ||
|
||
return $this->responseWithData($request, $response, $responseData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters