/** * Overrides parent::addInitializer in order to ensure default initializers are in expected positions. * * Always pushes `injectFactory` to top of initializer stack, and * `callElementInit` to the bottom. * * {@inheritDoc} */ public function addInitializer($initializer, $topOfStack = true) { $firstInitializer = [$this, 'injectFactory']; $lastInitializer = [$this, 'callElementInit']; foreach ([$firstInitializer, $lastInitializer] as $default) { if (false === ($index = array_search($default, $this->initializers))) { continue; } unset($this->initializers[$index]); } parent::addInitializer($initializer, $topOfStack); array_unshift($this->initializers, $firstInitializer); array_push($this->initializers, $lastInitializer); return $this; }