-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce cache controller service provider
- Loading branch information
Showing
6 changed files
with
147 additions
and
19 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,50 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Cache; | ||
|
||
defined('_JEXEC') or die; | ||
|
||
/** | ||
* Default factory for creating CacheController objects | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class CacheControllerFactory implements CacheControllerFactoryInterface | ||
{ | ||
/** | ||
* Method to get an instance of a cache controller. | ||
* | ||
* @param string $type The cache object type to instantiate | ||
* @param array $options Array of options | ||
* | ||
* @return CacheController | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
* @throws \RuntimeException | ||
*/ | ||
public function createCacheController($type = 'output', $options = array()): CacheController | ||
{ | ||
$type = strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $type)); | ||
|
||
$class = __NAMESPACE__ . '\\Controller\\' . ucfirst($type) . 'Controller'; | ||
|
||
if ($type == '') | ||
{ | ||
$class = CacheController::class; | ||
} | ||
|
||
// The class should now be loaded | ||
if (!class_exists($class)) | ||
{ | ||
throw new \RuntimeException('Unable to load Cache Controller: ' . $type, 500); | ||
} | ||
|
||
return new $class($options); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\CMS\Cache; | ||
|
||
defined('_JEXEC') or die; | ||
|
||
/** | ||
* Interface defining a factory which can create CacheController objects | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
interface CacheControllerFactoryInterface | ||
{ | ||
/** | ||
* Method to get an instance of a cache controller. | ||
* | ||
* @param string $type The cache object type to instantiate | ||
* @param array $options Array of options | ||
* | ||
* @return CacheController | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
* @throws \RuntimeException | ||
*/ | ||
public function createCacheController($type = 'output', $options = array()): CacheController; | ||
} |
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,47 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2018 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\Cache\CacheControllerFactory; | ||
use Joomla\CMS\Cache\CacheControllerFactoryInterface; | ||
use Joomla\DI\Container; | ||
use Joomla\DI\ServiceProviderInterface; | ||
|
||
/** | ||
* Service provider for the cache controller dependency | ||
* | ||
* @since 4.0 | ||
*/ | ||
class CacheController implements ServiceProviderInterface | ||
{ | ||
/** | ||
* Registers the service provider with a DI container. | ||
* | ||
* @param Container $container The DI container. | ||
* | ||
* @return void | ||
* | ||
* @since 4.0 | ||
*/ | ||
public function register(Container $container) | ||
{ | ||
$container->alias('cachecontroller.factory', CacheControllerFactoryInterface::class) | ||
->alias(CacheControllerFactory::class, CacheControllerFactoryInterface::class) | ||
->share( | ||
CacheControllerFactoryInterface::class, | ||
function (Container $container) | ||
{ | ||
return new CacheControllerFactory; | ||
}, | ||
true | ||
); | ||
} | ||
} |