private function registerCollectors() { $this->loader->registerNamespace('Shopware\\Plugin\\Debug', realpath(__DIR__ . '/../../../../Default/Core/Debug/') . '/'); $eventManager = Shopware()->Container()->get('events'); $utils = new Utils(); $errorHandler = $this->collection->get('ErrorHandler'); if ($this->Config()->get('logTemplateVars')) { $this->pushCollector(new TemplateVarCollector($eventManager)); } if ($this->Config()->get('logErrors')) { $this->pushCollector(new ErrorCollector($errorHandler, $utils)); } if ($this->Config()->get('logExceptions')) { $this->pushCollector(new ExceptionCollector($eventManager, $utils)); } if ($this->Config()->get('logDb')) { $this->pushCollector(new DatabaseCollector(Shopware()->Container()->get('db'))); } if ($this->Config()->get('logModel')) { $this->pushCollector(new DbalCollector(Shopware()->Container()->get('modelconfig'))); } if ($this->Config()->get('logTemplate')) { $this->pushCollector(new TemplateCollector(Shopware()->Container()->get('template'), $utils, Shopware()->Container()->get('kernel')->getRootDir())); } if ($this->Config()->get('logController')) { $this->pushCollector(new ControllerCollector($eventManager, $utils)); } if ($this->Config()->get('logEvents')) { $this->pushCollector(new EventCollector($eventManager, $utils)); } foreach ($this->collectors as $collector) { $collector->start(); } }
/** * @param \Enlight_Loader $loader * @param \Shopware_Components_Config $config * @param array $options * @return \Enlight_Class|\Zend_Mail_Transport_Abstract */ public function factory(\Enlight_Loader $loader, \Shopware_Components_Config $config, array $options) { if (!isset($options['type']) && !empty($config->MailerMailer) && $config->MailerMailer != 'mail') { $options['type'] = $config->MailerMailer; } if (empty($options['type'])) { $options['type'] = 'sendmail'; } if ($options['type'] == 'smtp') { if (!isset($options['username']) && !empty($config->MailerUsername)) { if (!empty($config->MailerAuth)) { $options['auth'] = $config->MailerAuth; } elseif (empty($options['auth'])) { $options['auth'] = 'login'; } $options['username'] = $config->MailerUsername; $options['password'] = $config->MailerPassword; } if (!isset($options['ssl']) && !empty($config->MailerSMTPSecure)) { $options['ssl'] = $config->MailerSMTPSecure; } if (!isset($options['port']) && !empty($config->MailerPort)) { $options['port'] = $config->MailerPort; } if (!isset($options['name']) && !empty($config->MailerHostname)) { $options['name'] = $config->MailerHostname; } if (!isset($options['host']) && !empty($config->MailerHost)) { $options['host'] = $config->MailerHost; } } if (!$loader->loadClass($options['type'])) { $transportName = ucfirst(strtolower($options['type'])); $transportName = 'Zend_Mail_Transport_' . $transportName; } else { $transportName = $options['type']; } unset($options['type'], $options['charset']); if ($transportName == 'Zend_Mail_Transport_Smtp') { $transport = \Enlight_Class::Instance($transportName, array($options['host'], $options)); } elseif (!empty($options)) { $transport = \Enlight_Class::Instance($transportName, array($options)); } else { $transport = \Enlight_Class::Instance($transportName); } /** @var $transport \Zend_Mail_Transport_Abstract */ \Enlight_Components_Mail::setDefaultTransport($transport); if (!isset($options['from']) && !empty($config->Mail)) { $options['from'] = array('email' => $config->Mail, 'name' => $config->Shopname); } if (!empty($options['from']['email'])) { \Enlight_Components_Mail::setDefaultFrom($options['from']['email'], !empty($options['from']['name']) ? $options['from']['name'] : null); } if (!empty($options['replyTo']['email'])) { \Enlight_Components_Mail::setDefaultReplyTo($options['replyTo']['email'], !empty($options['replyTo']['name']) ? $options['replyTo']['name'] : null); } return $transport; }
/** * @param Enlight_Event_EventManager $eventManager * @param array $options * @throws Exception */ public function __construct(\Enlight_Event_EventManager $eventManager, \Enlight_Loader $loader, $options) { $this->eventManager = $eventManager; if (!isset($options['proxyNamespace'])) { throw new \Exception('proxyNamespace has to be set.'); } if (!isset($options['proxyDir'])) { throw new \Exception('proxyDir has to be set.'); } $this->proxyFactory = new Enlight_Hook_ProxyFactory($this, $options['proxyNamespace'], $options['proxyDir']); $loader->registerNamespace($options['proxyNamespace'], $this->proxyFactory->getProxyDir()); }
/** * @param $params * @param $template * @return bool|mixed|string */ function smarty_function_flink($params, $template) { $file = $params['file']; /** @var $front Enlight_Controller_Front */ $front = Enlight_Application::Instance()->Front(); $request = $front->Request(); // check if we got an URI or a local link if (!empty($file) && strpos($file, '/') !== 0 && strpos($file, '://') === false) { $useIncludePath = $template->smarty->getUseIncludePath(); // try to find the file on the filesystem foreach ($template->smarty->getTemplateDir() as $dir) { if (file_exists($dir . $file)) { $file = realpath($dir) . DS . str_replace('/', DS, $file); break; } if ($useIncludePath) { if ($dir === '.' . DS) { $dir = ''; } if (($result = Enlight_Loader::isReadable($dir . $file)) !== false) { $file = $result; break; } } } if (method_exists(Enlight_Application::Instance(), 'DocPath')) { $docPath = Enlight_Application::Instance()->DocPath(); } else { $docPath = getcwd() . DIRECTORY_SEPARATOR; } // some clean up code if (strpos($file, $docPath) === 0) { $file = substr($file, strlen($docPath)); } // make sure we have the right separator for the web context if (DIRECTORY_SEPARATOR !== '/') { $file = str_replace(DIRECTORY_SEPARATOR, '/', $file); } if (strpos($file, './') === 0) { $file = substr($file, 2); } // if we did not find the file, we are returning a false if (strpos($file, '/') !== 0) { if (!file_exists($docPath . $file)) { //return false; } if ($request !== null) { $file = $request->getBasePath() . '/' . $file; } } } if (empty($file) && $request !== null) { $file = $request->getBasePath() . '/'; } if ($request !== null && strpos($file, '/') === 0 && !empty($params['fullPath'])) { $file = $request->getScheme() . '://' . $request->getHttpHost() . $file; } return $file; }
/** * @param Container $container * @param \Enlight_Loader $loader * @param \Enlight_Event_EventManager $eventManager * @param \Shopware $application * @param array $config * @return \Enlight_Plugin_PluginManager */ public function factory(Container $container, \Enlight_Loader $loader, \Enlight_Event_EventManager $eventManager, \Shopware $application, array $config) { $pluginManager = new \Enlight_Plugin_PluginManager($application); $container->load('Table'); if (!isset($config['namespaces'])) { $config['namespaces'] = array('Core', 'Frontend', 'Backend'); } foreach ($config['namespaces'] as $namespace) { $namespace = new \Shopware_Components_Plugin_Namespace($namespace); $pluginManager->registerNamespace($namespace); $eventManager->registerSubscriber($namespace->Subscriber()); } foreach (array('Local', 'Community', 'Default', 'Commercial') as $dir) { $loader->registerNamespace('Shopware_Plugins', Shopware()->AppPath('Plugins_' . $dir)); } return $pluginManager; }
/** * Creates the entity manager for the application. * * @param EventManager $eventManager * @param Configuration $config * @param \Enlight_Loader $loader * @param \Pdo $db * @param string $kernelRootDir * @param AnnotationDriver $modelAnnotation * * @return ModelManager */ public function factory(EventManager $eventManager, Configuration $config, \Enlight_Loader $loader, \PDO $db, $kernelRootDir, AnnotationDriver $modelAnnotation) { $vendorPath = $kernelRootDir . '/vendor'; // register standard doctrine annotations AnnotationRegistry::registerFile($vendorPath . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); // register symfony validation annotations AnnotationRegistry::registerAutoloadNamespace('Symfony\\Component\\Validator\\Constraint', realpath($vendorPath . '/symfony/validator')); $loader->registerNamespace('Shopware\\Models\\Attribute', $config->getAttributeDir()); // now create the entity manager and use the connection // settings we defined in our application.ini $conn = DriverManager::getConnection(array('pdo' => $db), $config, $eventManager); $conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $conn->getDatabasePlatform()->registerDoctrineTypeMapping('bit', 'boolean'); $entityManager = ModelManager::createInstance($conn, $config, $eventManager); LazyFetchModelEntity::setEntityManager($entityManager); return $entityManager; }
/** * Test case method */ public function testAddIncludePath3() { $old = Enlight_Loader::addIncludePath('.', Enlight_Loader::POSITION_REMOVE); $new = Enlight_Loader::explodeIncludePath(); $found = array_search('.', $new); Enlight_Loader::setIncludePath($old); $this->assertFalse($found); }
/** * @param string $templateDir * @param int|null $key * @return string */ public function resolveTemplateDir($templateDir, $key = null) { if ($this->eventManager !== null) { $templateDir = $this->eventManager->filter(__CLASS__ . '_ResolveTemplateDir', $templateDir, array('subject' => $this, 'key' => $key)); } $templateDir = Enlight_Loader::isReadable($templateDir); return $templateDir; }
/** * Returns whether the given request object is dispatchable. * Checks first if the controller class of the request object exists. * If the controller class exists, the enlight loader class checks if the controller path is readable. * * @param Enlight_Controller_Request_Request $request * @return bool|string */ public function isDispatchable(Enlight_Controller_Request_Request $request) { $className = $this->getControllerClass($request); if (!$className) { return false; } if (class_exists($className, false)) { return true; } $path = $this->getControllerPath($request); return Enlight_Loader::isReadable($path); }
function smarty_function_booster(array $params, Smarty_Internal_Template $template) { $root = $template; $type = isset($params['type']) ? $params['type'] : null; $media = isset($params['media']) ? $params['media'] : null; $src = isset($params['src']) ? $params['src'] : null; $output = isset($params['output']); // sanity checks if ($type !== 'css' && $type !== 'js') { throw new Exception('{booster type="css|js"} - unknown type "' . $type . '"'); } // TODO: allow arrays of src if (!$output && !$src) { throw new Exception('{booster src="/some/file.css"} - invalid src "' . $src . '"'); } // get all available templates $dirs = (array) $root->smarty->getTemplateDir(); $dirs += Enlight_Loader::explodeIncludePath(); // try to find the file on the filesystem foreach ($dirs as $dir) { $templateDir = str_ireplace(DOCPATH, '', $dir); if (file_exists($dir . $src)) { $src = $templateDir . $src; break; } } $filepath = DOCPATH . $src; if (!file_exists($filepath)) { throw new Exception('{booster src="' . $src . '"} file not found at "' . $filepath . '"'); } // store stuff in the root template (NOT Smarty)! while ($root->parent && $root->parent instanceof Smarty_Internal_Template) { $root = $root->parent; } // create booster $booster = $root->getTemplateVars('__booster'); if (!$booster) { $booster = new Booster(); // TODO: import options from somewhere $booster->js_minify = true; $booster->css_totalparts = 1; $booster->booster_cachedir = '../../../cache/templates'; $root->assign('__booster', $booster); } // create cache // Note: would've liked a reference, but can't count on getTemplateVars() allowing to return by ref :( $cache = $root->getTemplateVars('__booster_cache'); if (!$cache) { $cache = array('css' => array(), 'js' => array()); } // make sure paths are relative to the booster directory // they are to be provided absolute from the doc root // booster is supposed to be in the doc root // so prepending .. should work fine $src = '../../../' . $src; $result = ''; if ($output) { // We're using mod_rewrite but the booster builds up an strange // path if mod_rewrite is on, so we set it manually to false $booster->mod_rewrite = false; if ($type == 'css') { if (empty($cache['css'][$media])) { return $result; } $booster->css_source = $cache['css'][$media]; $cache['css'][$media] = array(); $booster->css_media = $media; $result = $booster->css_markup(); } else { $booster->js_source = $cache['js']; $cache['js'] = array(); $result = $booster->js_markup(); } } else { if ($type == 'css') { $cache['css'][$media][] = $src; } else { $cache['js'][] = $src; } } $root->assign('__booster_cache', $cache); return $result; }
/** * Include the auto load / tests the loading * * @return Enlight_Loader * @throws Exception */ protected function initLoader() { @(include_once 'Enlight/Loader.php'); if (!class_exists('Enlight_Loader')) { throw new Exception('Enlight loader could not be included. Please check the include path.'); } $loader = new Enlight_Loader(); $loader->registerNamespace('Enlight', 'Enlight/'); $loader->registerNamespace('Zend', 'Zend/'); return $loader; }
/** * Test enlight loader check file */ public function testEnlightLoaderCheckFile() { $this->assertTrue(Enlight_Loader::checkFile('H:\\Apache Group\\Apache\\htdocs\\shopware.php')); $this->assertFalse(Enlight_Loader::checkFile('H:\\Apache Group\\Apache\\htdocs\\shopware.php' . "")); }