-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Raistlfiren/root
Added root controller for api route
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 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,67 @@ | ||
<?php | ||
|
||
namespace Bolt\Extension\Bolt\JsonApi\Action; | ||
|
||
use Bolt\Config; | ||
use Bolt\Extension\Bolt\JsonApi\Response\ApiResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* Class RootAction | ||
* | ||
* @package Bolt\Extension\Bolt\JsonApi\Action | ||
*/ | ||
class RootAction | ||
{ | ||
/** @var Config $config */ | ||
protected $boltConfig; | ||
|
||
/** @var \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig */ | ||
protected $extensionConfig; | ||
|
||
/** @var string $boltVersion */ | ||
protected $boltVersion; | ||
|
||
/** @var string $jsonAPIVersion */ | ||
protected $jsonAPIVersion; | ||
|
||
/** | ||
* MenuAction constructor. | ||
* | ||
* @param Config $boltConfig | ||
* @param \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig | ||
* @param string $boltVersion | ||
* @param string $jsonAPIVersion | ||
*/ | ||
public function __construct(Config $boltConfig, \Bolt\Extension\Bolt\JsonApi\Config\Config $extensionConfig, $boltVersion, $jsonAPIVersion) | ||
{ | ||
$this->boltConfig = $boltConfig; | ||
$this->extensionConfig = $extensionConfig; | ||
$this->boltVersion = $boltVersion; | ||
$this->jsonAPIVersion = $jsonAPIVersion; | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* | ||
* @return ApiResponse | ||
*/ | ||
public function handle(Request $request) | ||
{ | ||
$data = 'API is active.'; | ||
$debug = $this->boltConfig->getConfig()['general']['debug']; | ||
|
||
if ($debug) { | ||
$data = [ | ||
'versions' => [ | ||
'bolt' => $this->boltVersion, | ||
'jsonapi' => $this->jsonAPIVersion | ||
] | ||
]; | ||
} | ||
|
||
return new ApiResponse([ | ||
'data' => $data, | ||
], $this->extensionConfig); | ||
} | ||
} |
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