Last active
September 27, 2015 06:23
-
-
Save drinkmaker/bb73c6f183a33554dfb2 to your computer and use it in GitHub Desktop.
How to convert PHP 5.3 to PHP 5.2
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 | |
/** | |
* Instantiate the container. | |
* | |
* Objects and parameters can be passed as argument to the constructor. | |
* | |
* @param array $values The parameters or objects. | |
*/ | |
public function __construct(array $values = array()) { | |
$self = $this; | |
$this->values = $values; | |
// register helpers | |
foreach ($this['config']->get('helper', array()) as $name => $class) { | |
$this[$name] = $this->share(function($self) use ($class) { return new $class($self); }); | |
} | |
} | |
/** | |
* Returns a closure that stores the result of the given closure for | |
* uniqueness in the scope of this instance. | |
* | |
* @param Closure $callable A closure to wrap for uniqueness | |
* | |
* @return Closure The wrapped closure | |
*/ | |
public static function share(Closure $callable) { | |
return function ($c) use ($callable) { | |
static $object; | |
if (null === $object) { | |
$object = $callable($c); | |
} | |
return $object; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment