public static function create(Modules $modules, Bindings $bindings, Singletons $singletons, CodeStorage $storage, Reflection $reflection) { $pointCuts = new PointCuts(); $jit = new JustInTimeBinder($bindings); $locator = new BindingLocator($bindings, $jit, $reflection); $moduleBinder = new ModuleBinder($bindings, $pointCuts); $configBinder = new ConfigBinder($bindings); $binder = new Binder($moduleBinder, $configBinder, $reflection); $builder = new BindingsBuilder($bindings, $modules, $binder, [new LateBindingVisitor($locator), new CircularProviderVisitor($bindings, $jit, $reflection), $marker = new SingletonMarkerVisitor(), new ConstantFoldingVisitor($bindings)], $singletons, $marker); $modulesAdapter = new ModulesAdapterFactory($builder, $singletons, $storage); $adapter = $modulesAdapter->get($modules); $singletons->setSize($adapter::SINGLETONS_SIZE); $aspect = AspectWeaver::create($modules, $storage, $reflection, $pointCuts, $singletons, $locator); return new FactoryFactory($modules, $locator, $builder, $storage, $reflection, $aspect); }
function U($path, $absolute = false, $querystring = []) { return Singletons::U()->u($path, $absolute, $querystring); }
var_dump($anotherObj === SingletonChild::getInstance()); // bool(true) // ----------- /** * Class Singletons * Register singletons in class */ class Singletons { private static $singleton = array(); public static function getSingleton($class) { if (!isset(self::$singleton[$class])) { self::$singleton[$class] = new $class(); } return self::$singleton[$class]; } } class aSingleton { public $i; public function test() { ++$this->i; echo get_class() . " called {$this->i} times\n"; } } /** @var aSingleton $obj */ $obj = Singletons::getSingleton('aSingleton'); $obj->test(); $obj->test();
function T() { return Singletons::T(); }
public function setSize($size) { parent::setSize($size - $this->super->getSize()); }