Last active
August 29, 2015 14:06
-
-
Save nickpeirson/9478538351a240e73229 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace CG\Di\Definition\RuntimeDefinition; | |
use CG\Di\Definition\RuntimeDefinition; | |
use Zend\Di\Definition\IntrospectionStrategy; | |
use Zend\Cache\Storage\StorageInterface; | |
use Zend\Cache\Storage\Adapter\Memory; | |
class Cache extends RuntimeDefinition | |
{ | |
protected $cache; | |
public function __construct( | |
IntrospectionStrategy $introspectionStrategy = null, | |
array $explicitClasses = null, | |
StorageInterface $cache = null | |
) { | |
parent::__construct($introspectionStrategy = null, $explicitClasses = null); | |
if (is_null($cache)) { | |
return; | |
} | |
$this->cache = $cache; | |
register_shutdown_function([$this, 'persistDefinitions']); | |
} | |
public function persistDefinitions() | |
{ | |
$this->cache->setItem( | |
'classes', | |
array_merge( | |
$this->classes, | |
$this->cache->getItem('classes') | |
); | |
); | |
} | |
} |
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
<?php | |
$definitions = new ArrayDefinition($cache->getItem('classes')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment