/** * This function is responsible to resolve the backend / frontend controller path. * * @param \Enlight_Event_EventArgs $args * @return string */ public function onGetCustomSortControllerPath(\Enlight_Event_EventArgs $args) { $this->templateManager->addTemplateDir($this->bootstrapPath . 'Views/'); switch ($args->getName()) { case 'Enlight_Controller_Dispatcher_ControllerPath_Backend_CustomSort': return $this->bootstrapPath . 'Controllers/Backend/CustomSort.php'; case 'Enlight_Controller_Dispatcher_ControllerPath_Widgets_CustomSort': return $this->bootstrapPath . 'Controllers/Widgets/CustomSort.php'; } }
/** * Generic callback function for all registered subscribers in this class. Will dispatch the event to * the anonymous function of the corresponding service * * @param \Enlight_Event_EventArgs $args * @return mixed */ public function load(\Enlight_Event_EventArgs $args) { // get registered service from event name $name = str_replace('Enlight_Bootstrap_InitResource_', '', $args->getName()); // call anonymous function in order to register service $method = self::$definitions[$name]; if (!$method) { throw new \RuntimeException("Service named {$name} not found"); } return $method(self::$container, $args); }
/** * @param \Enlight_Event_EventArgs $args * @return mixed */ public function onBenchmarkEvent(\Enlight_Event_EventArgs $args) { $event = $args->getName(); if (!isset($this->results[$event])) { $this->results[$event] = array(0 => true, 1 => 0, 2 => 0, 3 => microtime(true)); } if (empty($this->results[$event][0])) { $this->results[$event][0] = true; $this->results[$event][1] -= memory_get_peak_usage(true); $this->results[$event][2] -= microtime(true); } else { $this->results[$event][0] = false; $this->results[$event][1] += memory_get_peak_usage(true); $this->results[$event][2] += microtime(true); } return $args->getReturn(); }
/** * Logs all controller events into the internal log object. * Each logged events contains the event name, the execution time and the allocated peak of memory. * * @param Enlight_Event_EventArgs $args * @return void */ public function onBenchmarkEvent(Enlight_Event_EventArgs $args) { if (empty($this->results)) { $this->results[] = array('name', 'memory', 'time'); $this->startTime = microtime(true); $this->startMemory = memory_get_peak_usage(true); } $this->results[] = array( 0 => str_replace('Enlight_Controller_', '', $args->getName()), 1 => $this->formatMemory(memory_get_peak_usage(true) - $this->startMemory), 2 => $this->formatTime(microtime(true) - $this->startTime) ); }
/** * Internal listener function of each fired event in shopware. * * @param Enlight_Event_EventArgs $args * @return mixed */ public function onEvent(Enlight_Event_EventArgs $args) { if ($this->preventEventLog) { return $args->getReturn(); } $event = $args->getName(); $this->events[$event]['returns'][] = $args->getReturn(); $this->events[$event]['time'][] = microtime(true); return $args->getReturn(); }
/** * Standard event listener function for plugin controllers. * If the default event listener is used for the registration of a plugin controller, the following requirements must be fulfilled: * 1. The plugin directory must contain a 'Controller' subdirectory. * 2. The "Controllers" directory must contain a subdirectory which corresponds to the module (Frontend, Backend, Widgets or API) * 3. The controller must be filed in the module directory. * 4. The controller file must have the same name as the controller class. * * If all the requirements are fulfilled, the controller is registered automatically. * Additionally, the following plugin namespaces/directories are registered, if available: * 1. The 'Views' plugin directory is added as a template directory. * 2. The 'Snippets' plugin directory is added as a config directory. * 3. The 'Components' plugin directory is added as a component namespace. * * @param Enlight_Event_EventArgs $arguments * @throws Exception * @return string */ public function getDefaultControllerPath(Enlight_Event_EventArgs $arguments) { $eventName = $arguments->getName(); $eventName = str_replace('Enlight_Controller_Dispatcher_ControllerPath_', '', $eventName); $parts = explode('_', $eventName); $module = $parts[0]; $controller = $parts[1]; $path = $this->Path() . 'Controllers/' . ucfirst($module) . '/' . ucfirst($controller) . '.php'; if (!file_exists($path)) { throw new Enlight_Exception('Controller "' . $controller . '" can\'t load failure'); } //register plugin model directory if (file_exists($this->Path() . 'Models')) { $this->registerCustomModels(); } //register plugin views directory if (file_exists($this->Path() . 'Views')) { $this->Application()->Template()->addTemplateDir($this->Path() . 'Views/'); } //register plugin snippet directory if (file_exists($this->Path() . 'Snippets')) { $this->Application()->Snippets()->addConfigDir($this->Path() . 'Snippets/'); } //register plugin component directory if (file_exists($this->Path() . 'Components')) { $this->Application()->Loader()->registerNamespace('Shopware_Components', $this->Path() . 'Components/'); } return $path; }