forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added route function * Added ApiRouter class * Fixing phpcs errors * Fixed coding standard issues, wrong namespace * Added service provider for ApiRouter * Changed the name of getRouter to getApiRouter * Fixed some phpcs issues * Codestyle * Code style part 2 * Changed the delimiter of controller function
- Loading branch information
Showing
4 changed files
with
172 additions
and
4 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
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,90 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Router; | ||
use Joomla\Router\Router; | ||
|
||
/** | ||
* Joomla! API Router class | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class ApiRouter extends Router | ||
{ | ||
/** | ||
* Router instances container. | ||
* | ||
* @var array | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected static $instances = array(); | ||
|
||
/** | ||
* Creates routes map for CRUD | ||
* | ||
* @param string $baseName The base name of the component. | ||
* @param string $controller The name of the controller that contains CRUD functions. | ||
* @param array $defaults An array of default values that are used when the URL is matched. | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function createCRUDRoutes($baseName, $controller, $defaults = array()) | ||
{ | ||
$routes = array( | ||
array( | ||
'method' => 'GET', | ||
'pattern' => $baseName, | ||
'controller' => $controller . '.display', | ||
'defaults' => $defaults | ||
), | ||
array( | ||
'method' => 'GET', | ||
'pattern' => $baseName . '/new', | ||
'controller' => $controller . '.add', | ||
'defaults' => $defaults | ||
), | ||
array( | ||
'method' => 'GET', | ||
'pattern' => $baseName . '/:id', | ||
'controller' => $controller . '.display', | ||
'rules' => array('id' => '(\d+)'), | ||
'defaults' => $defaults | ||
), | ||
array( | ||
'method' => 'GET', | ||
'pattern' => $baseName . '/:id/edit', | ||
'controller' => $controller . '.edit', | ||
'rules' => array('id' => '(\d+)'), | ||
'defaults' => $defaults | ||
), | ||
array( | ||
'method' => 'POST', | ||
'pattern' => $baseName, | ||
'controller' => $controller . '.add', | ||
'defaults' => $defaults | ||
), | ||
array( | ||
'method' => 'PUT', | ||
'pattern' => $baseName . '/:id', | ||
'controller' => $controller . '.edit', | ||
'rules' => array('id' => '(\d+)'), | ||
'defaults' => $defaults | ||
), | ||
array( | ||
'method' => 'DELETE', | ||
'pattern' => $baseName . '/:id', | ||
'controller' => $controller . '.delete', | ||
'rules' => array('id' => '(\d+)'), | ||
'defaults' => $defaults | ||
), | ||
); | ||
$this->addRoutes($routes); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Service\Provider; | ||
|
||
defined('JPATH_PLATFORM') or die; | ||
|
||
use Joomla\CMS\Router\ApiRouter; | ||
use Joomla\DI\Container; | ||
use Joomla\DI\ServiceProviderInterface; | ||
|
||
/** | ||
* Service provider for the application's API router dependency | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class ApiRouter implements ServiceProviderInterface | ||
{ | ||
/** | ||
* Registers the service provider with a DI container. | ||
* | ||
* @param Container $container The DI container. | ||
* | ||
* @return void | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public function register(Container $container) | ||
{ | ||
$container->alias('ApiRouter', 'Joomla\CMS\Router\ApiRouter') | ||
->share( | ||
'Joomla\CMS\Router\ApiRouter', | ||
function (Container $container) | ||
{ | ||
return new ApiRouter; | ||
}, | ||
true | ||
); | ||
} | ||
} |