Created
July 29, 2012 07:54
-
-
Save wdalmut/3196566 to your computer and use it in GitHub Desktop.
Pimple DiC - Zend Cache Object
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
vendor | |
composer.phar |
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
{ | |
"minimum-stability": "dev", | |
"repositories": [ | |
{ | |
"type": "composer", | |
"url": "http://packages.zendframework.com/" | |
} | |
], | |
"require": { | |
"zendframework/zend-cache": "2.0.*", | |
"zendframework/zend-servicemanager": "2.0.*", | |
"zendframework/zend-eventmanager": "2.0.*", | |
"pimple/pimple": "1.0.0" | |
} | |
} |
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
{ | |
"hash": "8680af13d9b10bc96fa48f580e93ed71", | |
"packages": [ | |
{ | |
"package": "pimple/pimple", | |
"version": "1.0.0" | |
}, | |
{ | |
"package": "zendframework/zend-cache", | |
"version": "2.0.0-rc1" | |
}, | |
{ | |
"package": "zendframework/zend-eventmanager", | |
"version": "2.0.0-rc1" | |
}, | |
{ | |
"package": "zendframework/zend-servicemanager", | |
"version": "2.0.0-rc1" | |
}, | |
{ | |
"package": "zendframework/zend-stdlib", | |
"version": "2.0.0-rc1" | |
} | |
], | |
"packages-dev": null, | |
"aliases": [ | |
], | |
"minimum-stability": "dev", | |
"stability-flags": [ | |
] | |
} |
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 | |
require_once 'vendor/autoload.php'; | |
class A { | |
/** | |
* @var B The B var | |
*/ | |
private $_b; | |
public function __construct(\B $b) { | |
$this->_b = $b; | |
} | |
public function intensiveTask($param1, $param2) { | |
return $param1 . " " . $this->_b->intensiveB() . " " . $param2; | |
} | |
} | |
class B { | |
private $_c; | |
public function __construct(\C $c) { | |
$this->_c = $c; | |
} | |
public function intensiveB() { | |
return $this->_c->compute(); | |
} | |
} | |
class C { | |
private $_c; | |
public function __construct() { | |
$this->_c = "Created C"; | |
} | |
public function compute() { | |
return $this->_c; | |
} | |
} | |
$container = new Pimple(); | |
$container["options"] = function($c) { | |
$options = new \Zend\Cache\Pattern\PatternOptions(); | |
$options->setStorage($c["storage"]); | |
$options->setObject($c["model"]); | |
return $options; | |
}; | |
$container["storage"] = function($c) { | |
$storage = new \Zend\Cache\Storage\Adapter\Memory(); | |
return $storage; | |
}; | |
$container["model"] = function($c) { | |
$model = new \A(new \B(new \C())); | |
return $model; | |
}; | |
$container["proxy"] = function($c) { | |
$cache = new \Zend\Cache\Pattern\ObjectCache(); | |
$cache->setOptions($c["options"]); | |
return $cache; | |
}; | |
echo $container["proxy"]->intensiveTask("pimple", "ok") . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment