/** * @param $params * @param $template * @return void * @throws Exception */ function smarty_function_compileLess($params, $template) { $time = $params['timestamp']; $output = $params['output']; /**@var $pathResolver \Shopware\Components\Theme\PathResolver*/ $pathResolver = Shopware()->Container()->get('theme_path_resolver'); /**@var $shop \Shopware\Models\Shop\Shop*/ $shop = Shopware()->Container()->get('shop'); /**@var $settings \Shopware\Models\Theme\Settings*/ $settings = Shopware()->Container()->get('theme_service')->getSystemConfiguration(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT); /** @var $front Enlight_Controller_Front */ $front = Enlight_Application::Instance()->Front(); $secure = $front->Request()->isSecure(); $file = $pathResolver->getCssFilePath($shop, $time); $url = $pathResolver->formatPathToUrl($file, $shop, $secure); if (!$settings->getForceCompile() && file_exists($file)) { // see: http://stackoverflow.com/a/9473886 $template->assign($output, [$url]); return; } /**@var $compiler \Shopware\Components\Theme\Compiler*/ $compiler = Shopware()->Container()->get('theme_compiler'); $compiler->compileLess($time, $shop->getTemplate(), $shop); $template->assign($output, [$url]); }
/** * Returns a number in local specific format. * * @link http://framework.zend.com/manual/de/zend.locale.parsing.html * @param int|float $value * @param array $format * @return mixed */ function smarty_modifier_number($value, $format = array()) { if (empty($format['locale'])) { $format['locale'] = Enlight_Application::Instance()->Locale(); } return Zend_Locale_Format::toNumber($value, $format); }
/** * Format an given Date to local specific rules. * * @link http://framework.zend.com/manual/de/zend.date.constants.html * @param string $value * @param string $format * @param string $type * @return int|mixed|null|string */ function smarty_modifier_date($value, $format = null, $type = null) { if ($value === 'r') { $value = $format; $format = 'r'; $type = 'php'; } if (empty($value)) { return ''; } if (!empty($format) && is_string($format)) { if (defined('Zend_Date::' . strtoupper($format))) { $format = constant('Zend_Date::' . strtoupper($format)); } } if (!empty($type) && is_string($type)) { $type = strtolower($type); } /** @var Zend_Locale $locale */ $locale = Enlight_Application::Instance()->Bootstrap()->getResource('locale'); if (is_string($value)) { $value = strtotime($value); } elseif ($value instanceof DateTime) { /** @var $value DateTime */ $value = $value->getTimestamp(); } $date = new Zend_Date($value, Zend_Date::TIMESTAMP, $locale); $value = $date->toString($format, $type); $value = htmlentities($value, ENT_COMPAT, 'UTF-8', false); return $value; }
/** * App path test case. */ public function testPathsExtends() { $app = Enlight_Application::Instance(); $this->assertFileExists($app->Path('Enlight')); $this->assertFileExists($app->CorePath('Components')); $this->assertFileExists($app->ComponentsPath('Db')); }
/** * Formats a given decimal value to a local aware currency value * * * @link http://framework.zend.com/manual/de/zend.currency.options.html * @param float $value Value can have a coma as a decimal separator * @param array $config * @param string $position where the currency symbol should be displayed * @return float|string */ function smarty_modifier_currency($value, $config = null, $position = null) { if (!Enlight_Application::Instance()->Bootstrap()->hasResource('Currency')) { return $value; } if (!empty($config) && is_string($config)) { $config = strtoupper($config); if (defined('Zend_Currency::' . $config)) { $config = array('display' => constant('Zend_Currency::' . $config)); } else { $config = array(); } } else { $config = array(); } if (!empty($position) && is_string($position)) { $position = strtoupper($position); if (defined('Zend_Currency::' . $position)) { $config['position'] = constant('Zend_Currency::' . $position); } } $currency = Enlight_Application::Instance()->Currency(); $value = floatval(str_replace(',', '.', $value)); $value = $currency->toCurrency($value, $config); if (function_exists('mb_convert_encoding')) { $value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8'); } $value = htmlentities($value, ENT_COMPAT, 'UTF-8', false); return $value; }
/** * @param $args * @param $compiler * @return string */ public function compile($args, $compiler) { $_attr = $this->getAttributes($compiler, $args); if (!Enlight_Application::Instance()->Bootstrap()->hasResource('Config')) { if (!isset($_attr['default'])) { $_attr['default'] = 'null'; } return '<?php echo ' . $_attr['default'] . '; ?>'; } if (!preg_match('/^([\'"]?)[a-zA-Z0-9]+(\\1)$/', $_attr['name'], $match)) { $return = $_attr['name']; if (isset($_attr['default'])) { $return .= ', ' . $_attr['default']; } if (isset($_attr['namespace'])) { return '<?php echo Enlight_Application::Instance()->Config()->getByNamespace(' . $_attr['namespace'] . ', ' . $return . '); ?>'; } return '<?php echo Enlight_Application::Instance()->Config()->get(' . $return . '); ?>'; } $name = substr($_attr['name'], 1, -1); if (isset($_attr['namespace'])) { $namespace = substr($_attr['namespace'], 1, -1); $value = Enlight_Application::Instance()->Config()->getByNamespace($namespace, $name); } else { $value = Enlight_Application::Instance()->Config()->get($name); } if ($value !== null) { return '<?php echo ' . var_export($value, true) . ';?>'; } if (isset($_attr['default'])) { return '<?php echo ' . $_attr['default'] . ';?>'; } return null; }
/** * @param $args * @param $compiler * @return string */ public function compile($args, $compiler) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); // default 'false' for all option flags not set foreach ($_attr as $index => $param) { if ($param === false) { unset($_attr[$index]); } elseif ($param === true) { $_attr[$index] = "'1'"; } } $params = array(); foreach ($_attr as $index => $param) { if (!preg_match('/^([\'"]?)[a-zA-Z0-9]+(\\1)$/', $param, $match) || !empty($_attr['appendSession'])) { $params = ''; foreach ($_attr as $index => $param) { $params .= var_export($index, true) . ' => ' . $param . ', '; } return '<?php echo Enlight_Application::Instance()->Front()->Router()->assemble(array(' . $params . ')); ?>'; } $params[$index] = substr($param, 1, -1); } $url = Enlight_Application::Instance()->Front()->Router()->assemble($params); return '<?php echo ' . var_export($url, true) . ';?>'; }
/** * @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; }
/** * Returns the test database connection. * * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection */ public function getConnection() { if ($this->connection === null) { $pdo = Enlight_Application::Instance()->Db()->getConnection(); $this->connection = $this->createDefaultDBConnection($pdo); } return $this->connection; }
/** * Function to get access to the Enlight2 Config system. * * The params array knows the key * - name : Name of the config parameter which should be requested * - default : Default value if the queried config key does not exists * * @param array $params * @param mixed $smarty * @param string $template * * @return mixed */ function smarty_function_config($params, $smarty, $template) { $config = Enlight_Application::Instance()->Bootstrap()->hasResource('Config'); if (empty($params['name']) || $config) { return null; } return Enlight_Application::Instance()->Config()->get($params['name'], isset($params['default']) ? $params['default'] : null); }
/** * Constructor can be injected with a read / write adapter object * * @param Enlight_Components_Cron_Adapter $adapter * @param Enlight_Event_EventManager|null $eventManager * @return Enlight_Components_Cron_Manager */ public function __construct(Enlight_Components_Cron_Adapter $adapter, Enlight_Event_EventManager $eventManager = null) { $this->setAdapter($adapter); if (is_null($eventManager)) { $eventManager = Enlight_Application::Instance()->Events(); } $this->setEventManager($eventManager); }
/** * Test case. */ public function testSetIncludePaths() { $app = Enlight_Application::Instance(); $options = $app->getOptions(); $options['includepaths'] = $app->Loader()->explodeIncludePath(); $app->setOptions($options); $this->assertNotEmpty(get_include_path()); }
/** * Standard set up for every test - just disable auth */ public function setUp() { parent::setUp(); $proxy = Enlight_Application::Instance()->Hooks()->getProxy('Shopware_Controllers_Backend_ImportExport'); $this->controller = new $proxy(new Enlight_Controller_Request_RequestTestCase(), new Enlight_Controller_Response_ResponseTestCase()); // disable auth and acl Shopware()->Plugins()->Backend()->Auth()->setNoAuth(); Shopware()->Plugins()->Backend()->Auth()->setNoAcl(); }
/** * Instantiates a plugin from the plugin namespace and adds it to the internal plugins array. * * @param string $name * @param string $prefix * @param string|null $file * @return Enlight_Plugin_Namespace_Loader */ protected function initPlugin($name, $prefix, $file = null) { $class = implode('_', array($prefix, $name, 'Bootstrap')); if (!class_exists($class, false)) { Enlight_Application::Instance()->Loader()->loadClass($class, $file); } $plugin = new $class($name, $this); $this->plugins[$name] = $plugin; return $this; }
/** * Returns the current action's name * * The params array knows the following keys * - name : The name of the action to call * - params : optional params array for the specific action call * * @param $params * @param Enlight_Template_Default $template * @return string * @throws Exception */ function smarty_function_controllerAction($params, Enlight_Template_Default $template) { /** @var $front Enlight_Controller_Front */ $front = Enlight_Application::Instance()->Front(); $request = $front->Request(); if (empty($request) || !$request instanceof Zend_Controller_Request_Abstract) { $e = new Exception('Controller view helper requires a valid request object in the front controller instance'); throw $e; } return $request->getActionName(); }
/** * Returns known translations. * * @link http://framework.zend.com/manual/de/zend.locale.functions.html * @param string $value * @param string $path * @param string $locale * @return string|null */ function smarty_modifier_translate($value = null, $path = null, $locale = null) { if (!Enlight_Application::Instance()->Bootstrap()->hasResource('Locale')) { return $value; } if ($locale === null) { $locale = Enlight_Application::Instance()->Locale(); } if ($path == 'currency') { $path = 'nametocurrency'; } return $locale->getTranslation($value, $path, $locale); }
/** * Method to fast deploy a query to enlight * * The params array knows the following keys * - name : The name of the action to call * - params : optional params array for the specific action call * * @param $params * @param Enlight_Template_Default $template * @return string * @throws Exception */ function smarty_function_action($params, Enlight_Template_Default $template) { /** @var $front Enlight_Controller_Front */ $front = Enlight_Application::Instance()->Front(); $dispatcher = clone $front->Dispatcher(); $modules = $dispatcher->getControllerDirectory(); if (empty($modules)) { $e = new Exception('Action helper depends on valid front controller instance'); //$e->setView($view); throw $e; } $request = $front->Request(); $response = $front->Response(); if (empty($request) || empty($response)) { $e = new Exception('Action view helper requires both a registered request and response object in the front controller instance'); //$e->setView($view); throw $e; } if (isset($params['name'])) { $params['action'] = $params['name']; unset($params['name']); } if (isset($params['params'])) { $userParams = (array) $params['params']; unset($params['params']); } else { $userParams = array(); } $params = array_merge($userParams, $params); $request = clone $request; $response = clone $response; $request->clearParams(); $response->clearHeaders()->clearRawHeaders()->clearBody(); if (isset($params['module'])) { $request->setModuleName($params['module'])->setControllerName('index')->setActionName('index'); } if (isset($params['controller'])) { $request->setControllerName($params['controller'])->setActionName('index'); } $request->setParam('_isSubrequest', true); $request->setActionName(isset($params['action']) ? $params['action'] : 'index'); $request->setParams($params)->setDispatched(true); $dispatcher->dispatch($request, $response); if (!$request->isDispatched() || $response->isRedirect()) { // forwards and redirects render nothing return ''; } $return = $response->getBody(); return $return; }
/** * Builds an Enlight Link based on given controller and action. * The params array knows the following key: * - file : this key must be filled with a filename * - fullpath : if this key is filled, a whole link will be returned http[s]://.... * * @param array $params * @param Enlight_Template_Default $template * @return bool|mixed|string */ function smarty_function_link($params, Enlight_Template_Default $template) { if (empty($params['file'])) { return false; } $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 (strpos($file, '/') !== 0 && strpos($file, '://') === false) { // we've got a file which looks like a link $dirs = (array) $template->smarty->getTemplateDir(); // lets guess the webroot, if we are running inside an Enlight2 application // we are able to get the right path from the configs if (method_exists(Enlight_Application::Instance(), 'DocPath')) { $docPath = Enlight_Application::Instance()->DocPath(); } else { // otherwise assume we are in the webroot $docPath = getcwd() . DIRECTORY_SEPARATOR; } // try to find the file on the filesystem foreach ($dirs as $dir) { if (file_exists($dir . $file)) { $file = $dir . $file; break; } } // 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 we did not find the file, we are returning a false if (strpos($file, '/') !== 0) { if (!file_exists($docPath . $file)) { return false; } $file = $request->getBasePath() . '/' . $file; } } if (strpos($file, '/') === 0 && !empty($params['fullPath'])) { $file = $request->getScheme() . '://' . $request->getHttpHost() . $file; } return $file; }
function content_5642400ed5aa93_29200754($_smarty_tpl) { if ($_smarty_tpl->tpl_vars['sMenu']->value[$_smarty_tpl->tpl_vars['sGroup']->value]) { ?> <ul class="service--list is--rounded" role="menu"> <?php $_smarty_tpl->tpl_vars['item'] = new Smarty_Variable(); $_smarty_tpl->tpl_vars['item']->_loop = false; $_from = $_smarty_tpl->tpl_vars['sMenu']->value[$_smarty_tpl->tpl_vars['sGroup']->value]; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); } foreach ($_from as $_smarty_tpl->tpl_vars['item']->key => $_smarty_tpl->tpl_vars['item']->value) { $_smarty_tpl->tpl_vars['item']->_loop = true; ?> <li class="service--entry" role="menuitem"> <a class="service--link" href="<?php if ($_smarty_tpl->tpl_vars['item']->value['link']) { echo $_smarty_tpl->tpl_vars['item']->value['link']; } else { echo htmlspecialchars(Enlight_Application::Instance()->Front()->Router()->assemble(array('controller' => 'custom', 'sCustom' => $_smarty_tpl->tpl_vars['item']->value['id'], 'title' => $_smarty_tpl->tpl_vars['item']->value['description']))); } ?> " title="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['item']->value['description'], ENT_QUOTES, 'utf-8', true); ?> " <?php if ($_smarty_tpl->tpl_vars['item']->value['target']) { ?> target="<?php echo $_smarty_tpl->tpl_vars['item']->value['target']; ?> "<?php } ?> > <?php echo $_smarty_tpl->tpl_vars['item']->value['description']; ?> </a> </li> <?php } ?> </ul> <?php } }
/** * Returns the class name of the given class. If no class is given, the class will drawn by * get_called_class(). If the given class has an hook proxy the function will return the proxy class. * * @param mixed $class * @return string */ public static function getClassName($class = null) { if (empty($class)) { if (function_exists('get_called_class')) { $class = get_called_class(); } else { throw new Enlight_Exception('Method not supported'); } } if (is_object($class)) { $class = get_class($class); } elseif (!class_exists($class)) { throw new Enlight_Exception('Class ' . $class . ' does not exist and could not be loaded'); } if (in_array('Enlight_Hook', class_implements($class))) { $class = Enlight_Application::Instance()->Hooks()->getProxy($class); } return $class; }
/** * Returns application instance * * @param Shopware $newInstance * @return Shopware */ function Shopware($newInstance = null) { static $instance; if (isset($newInstance)) { $oldInstance = $instance; $instance = $newInstance; return $oldInstance; } elseif (!isset($instance)) { $instance = Enlight_Application::Instance(); } return $instance; }
function content_5642402b70bf43_21129011($_smarty_tpl) { ?> <div class="product--actions"> <?php ob_start(); echo 1; $_tmp1 = ob_get_clean(); if ($_tmp1) { ?> <a href="<?php echo htmlspecialchars(Enlight_Application::Instance()->Front()->Router()->assemble(array('controller' => 'compare', 'action' => 'add_article', 'articleID' => $_smarty_tpl->tpl_vars['sArticle']->value['articleID']))); ?> " title="<?php $_smarty_tpl->smarty->_tag_stack[] = array('snippet', array('name' => 'ListingBoxLinkCompare', 'namespace' => 'frontend/listing/box_article')); $_block_repeat = true; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => 'ListingBoxLinkCompare', 'namespace' => 'frontend/listing/box_article'), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); ?> Vergleichen<?php $_block_content = ob_get_clean(); $_block_repeat = false; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => 'ListingBoxLinkCompare', 'namespace' => 'frontend/listing/box_article'), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> " class="product--action action--compare" data-product-compare-add="true" rel="nofollow"> <i class="icon--compare"></i> <?php $_smarty_tpl->smarty->_tag_stack[] = array('snippet', array('name' => 'ListingBoxLinkCompare', 'namespace' => 'frontend/listing/box_article')); $_block_repeat = true; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => 'ListingBoxLinkCompare', 'namespace' => 'frontend/listing/box_article'), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); ?> Vergleichen<?php $_block_content = ob_get_clean(); $_block_repeat = false; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => 'ListingBoxLinkCompare', 'namespace' => 'frontend/listing/box_article'), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> </a> <?php } ?> <a href="<?php echo htmlspecialchars(Enlight_Application::Instance()->Front()->Router()->assemble(array('controller' => 'note', 'action' => 'add', 'ordernumber' => $_smarty_tpl->tpl_vars['sArticle']->value['ordernumber']))); ?> " title="<?php ob_start(); $_smarty_tpl->smarty->_tag_stack[] = array('snippet', array('name' => 'DetailLinkNotepad', 'namespace' => 'frontend/listing/box_article')); $_block_repeat = true; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => 'DetailLinkNotepad', 'namespace' => 'frontend/listing/box_article'), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); echo "Auf den Merkzettel"; $_block_content = ob_get_clean(); $_block_repeat = false; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => 'DetailLinkNotepad', 'namespace' => 'frontend/listing/box_article'), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); $_tmp2 = ob_get_clean(); echo htmlspecialchars($_tmp2, ENT_QUOTES, 'utf-8', true); ?> " class="product--action action--note" data-ajaxUrl="<?php echo htmlspecialchars(Enlight_Application::Instance()->Front()->Router()->assemble(array('controller' => 'note', 'action' => 'ajaxAdd', 'ordernumber' => $_smarty_tpl->tpl_vars['sArticle']->value['ordernumber']))); ?> " data-text="<?php $_smarty_tpl->smarty->_tag_stack[] = array('snippet', array('name' => "DetailNotepadMarked", 'namespace' => 'frontend/listing/box_article')); $_block_repeat = true; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => "DetailNotepadMarked", 'namespace' => 'frontend/listing/box_article'), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); ?> Gemerkt<?php $_block_content = ob_get_clean(); $_block_repeat = false; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => "DetailNotepadMarked", 'namespace' => 'frontend/listing/box_article'), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> " rel="nofollow"> <i class="icon--heart"></i> <span class="action--text"><?php $_smarty_tpl->smarty->_tag_stack[] = array('snippet', array('name' => "DetailLinkNotepadShort", 'namespace' => 'frontend/listing/box_article')); $_block_repeat = true; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => "DetailLinkNotepadShort", 'namespace' => 'frontend/listing/box_article'), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); ?> Merken<?php $_block_content = ob_get_clean(); $_block_repeat = false; echo Enlight_Components_Snippet_Resource::compileSnippetBlock(array('name' => "DetailLinkNotepadShort", 'namespace' => 'frontend/listing/box_article'), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); ?> </span> </a> </div><?php }
/** * Returns the test database connection. * * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection */ protected function getConnection() { $pdo = Enlight_Application::Instance()->Db()->getConnection(); return $this->createDefaultDBConnection($pdo); }
/** * Tests set up method */ public function setUp() { parent::setUp(); $app = Enlight_Application::Instance(); $app->Bootstrap()->loadResource('Plugins'); }
/** * Generate the class source code for the hooked method of the given class. * First all methods of the class are iterated. * Final, static, magic and private methods can't be hooked. * If the method is hooked, enlight iterates all method parameters to generate * the parameter definition. At last all hooked methods are implemented by the * $proxyMethodTemplate. * * @param unknown_type $class * @return unknown */ protected function generateMethods($class) { $rc = new ReflectionClass($class); $methodsArray = array(); $methods = ''; //iterate all class methods foreach ($rc->getMethods() as $rm) { //final, static and private methods can't be hooked. if ($rm->isFinal() || $rm->isStatic() || $rm->isPrivate()) { continue; } if (substr($rm->getName(), 0, 2) == '__') { continue; } //checks if the current method hooks exists. if (!Enlight_Application::Instance()->Hooks()->hasHooks($class, $rm->getName())) { continue; } //adds the hooked method to the array. $methodsArray[] = $rm->getName(); $params = ''; $proxy_params = ''; $array_params = ''; //iterates all parameters to generate the parameter definition. foreach ($rm->getParameters() as $rp) { if ($params) { $params .= ', '; $proxy_params .= ', '; $array_params .= ', '; } if ($rp->isPassedByReference()) { $params .= '&'; } $params .= '$' . $rp->getName(); $proxy_params .= '$' . $rp->getName(); $array_params .= '\'' . $rp->getName() . '\'=>$' . $rp->getName(); if ($rp->isOptional()) { $params .= ' = ' . str_replace("\n", '', var_export($rp->getDefaultValue(), true)); } } $modifiers = Reflection::getModifierNames($rm->getModifiers()); $modifiers = implode(' ', $modifiers); $search = array('<methodName>', '<methodModifiers>', '<methodParameters>', '<proxyMethodParameters>', '<arrayMethodParameters>', '<className>'); $replace = array($rm->getName(), $modifiers, $params, $proxy_params, $array_params, $class); $method = $this->proxyMethodTemplate; $method = str_replace($search, $replace, $method); $methods .= $method; } return array('array' => $methodsArray, 'methods' => $methods); }
/** * If the given request is not dispatchable, the default controller is set. * Then it tries to load the controller class and appends the hook proxies. * If the hook proxies are added, the dispatched flag of the request object is set to true. * If the disableOutputBuffering parameter isn't set, the output buffering starts. * After that, run the dispatch on the controller. * At the ending the body is added to the response object. * * @param Enlight_Controller_Request_Request $request * @param Enlight_Controller_Response_Response $response * @throws Enlight_Controller_Exception|Enlight_Exception|Exception */ public function dispatch(Enlight_Controller_Request_Request $request, Enlight_Controller_Response_Response $response) { $this->setResponse($response); if (!$this->isDispatchable($request)) { throw new Enlight_Controller_Exception('Controller "' . $request->getControllerName() . '" not found', Enlight_Controller_Exception::Controller_Dispatcher_Controller_Not_Found); } $class = $this->getControllerClass($request); $path = $this->getControllerPath($request); try { Enlight_Application::Instance()->Loader()->loadClass($class, $path); } catch (Exception $e) { throw new Enlight_Exception('Controller "' . $class . '" can\'t load failure'); } $proxy = Enlight_Application::Instance()->Hooks()->getProxy($class); /** @var $controller Enlight_Controller_Action */ $controller = new $proxy($request, $response); $controller->setFront($this->Front()); if ($controller instanceof ContainerAwareInterface) { $container = Enlight_Application::Instance()->Container(); $controller->setContainer($container); } $action = $this->getActionMethod($request); $request->setDispatched(true); $disableOb = $this->Front()->getParam('disableOutputBuffering'); $obLevel = ob_get_level(); if (empty($disableOb)) { ob_start(); } try { $controller->dispatch($action); } catch (Exception $e) { $curObLevel = ob_get_level(); if ($curObLevel > $obLevel) { do { ob_get_clean(); $curObLevel = ob_get_level(); } while ($curObLevel > $obLevel); } throw $e; } if (empty($disableOb)) { $content = ob_get_clean(); $response->appendBody($content); } }
* @example The following example illustrates a js compression: * {booster type="js" src="frontend/_resources/javascript/jquery.shopware.js} * {booster type="js" output=1} * * @category Enlight * @package Enlight_Template_Plugins * @copyright Copyright (c) 2011, shopware AG (http://www.shopware.de) * @license http://enlight.de/license New BSD License * @version $Id$ * @author $Author$ * @author rodneyrehm (https://github.com/rodneyrehm) * @author S.Pohl */ // Terminate the path to the document root if (method_exists(Enlight_Application::Instance(), 'DocPath')) { $docPath = Enlight_Application::Instance()->DocPath(); } else { $docPath = getcwd() . DIRECTORY_SEPARATOR; } // Define booster root and include it define('DOCPATH', $docPath); define('BOOSTER_HTDOCS', DOCPATH . 'engine' . DIRECTORY_SEPARATOR . 'Library' . DIRECTORY_SEPARATOR . 'Booster'); require_once BOOSTER_HTDOCS . '/booster_inc.php'; 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
/** * @param $args * @param $compiler * @return string */ public function compile($args, $compiler) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); // Removes the arguments that were not in the original. $noArgs = array(); foreach ($args as $arg) { if (is_array($arg)) { $noArgs[] = key($arg); } else { $noArgs[] = trim($arg, "'"); } } $noArgs = array_diff($this->option_flags, $noArgs); foreach ($noArgs as $noArg) { unset($_attr[$noArg]); } // default 'false' for all option flags not set foreach ($_attr as $index => $param) { if ($param === false) { $_attr[$index] = "'0'"; } elseif ($param === true) { $_attr[$index] = "'1'"; } } $params = array(); foreach ($_attr as $index => $param) { if (!preg_match('/^([\'"]?)[a-zA-Z0-9]+(\\1)$/', $param, $match) || !empty($_attr['appendSession'])) { $params = ''; foreach ($_attr as $index => $param) { $params .= var_export($index, true) . ' => ' . $param . ', '; } return '<?php echo Enlight_Application::Instance()->Front()->Router()->assemble(array(' . $params . ')); ?>'; } $params[$index] = is_numeric($param) ? $param : substr($param, 1, -1); } $url = Enlight_Application::Instance()->Front()->Router()->assemble($params); return '<?php echo ' . var_export($url, true) . ';?>'; }
/** * Dispatch function of the front controller. * * If the flags noErrorHandler and noViewRenderer aren't set, the error handler and the view renderer * plugins will be loaded. After the plugins loaded the Enlight_Controller_Front_StartDispatch * event is notified. * After the event is done, enlight sets the router, dispatcher, request and response object automatically. * If the objects has been set, the Enlight_Controller_Front_RouteStartup event is notified. * After the event is done, the route routes the request to controller/action. * Then the Enlight_Controller_Front_RouteShutdown event and the Enlight_Controller_Front_DispatchLoopStartup * event are notified. After this events the controller runs the dispatch * of the request unless according to request everything was dispatched. During the dispatch * two events are notified:<br> * - Enlight_Controller_Front_PreDispatch => before the dispatch<br> * - Enlight_Controller_Front_PostDispatch => after the dispatch<br><br> * When everything is dispatched the Enlight_Controller_Front_DispatchLoopShutdown event will be notified. * At last the response is sent. As well as the dispatch, two events are notified: * - Enlight_Controller_Front_SendResponse => before the response is sent<br> * - Enlight_Controller_Front_AfterSendResponse => after the response is sent * * @throws Exception * @return Enlight_Controller_Response_ResponseHttp */ public function dispatch() { if (!$this->getParam('noErrorHandler')) { $this->Plugins()->load('ErrorHandler'); } if (!$this->getParam('noViewRenderer')) { $this->Plugins()->load('ViewRenderer'); } Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_StartDispatch', array('subject' => $this)); if (!$this->router) { $this->setRouter('Enlight_Controller_Router_Default'); } if (!$this->dispatcher) { $this->setDispatcher('Enlight_Controller_Dispatcher_Default'); } if (!$this->request) { $this->setRequest('Enlight_Controller_Request_RequestHttp'); } if (!$this->response) { $this->setResponse('Enlight_Controller_Response_ResponseHttp'); } try { /** * Notify plugins of router startup */ Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_RouteStartup', array('subject' => $this)); /** * Route request to controller/action, if a router is provided */ try { $this->router->route($this->request); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } /** * Notify plugins of router completion */ Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_RouteShutdown', array('subject' => $this, 'request' => $this->Request())); /** * Notify plugins of dispatch loop startup */ Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_DispatchLoopStartup', array('subject' => $this, 'request' => $this->Request())); /** * Attempts to dispatch the controller/action. If the $this->request * indicates that it needs to be dispatched, it moves to the next * action in the request. */ do { $this->request->setDispatched(true); /** * Notify plugins of dispatch startup */ try { Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_PreDispatch', array('subject' => $this, 'request' => $this->Request())); /** * Skip requested action if preDispatch() has reset it */ if (!$this->request->isDispatched()) { continue; } /** * Dispatch request */ try { $this->dispatcher->dispatch($this->request, $this->response); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } /** * Notify plugins of dispatch completion */ Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_PostDispatch', array('subject' => $this, 'request' => $this->Request())); } while (!$this->request->isDispatched()); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } /** * Notify plugins of dispatch loop completion */ try { Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_DispatchLoopShutdown', array('subject' => $this)); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->response->setException($e); } if ($this->returnResponse()) { return $this->response; } if (!Enlight_Application::Instance()->Events()->notifyUntil('Enlight_Controller_Front_SendResponse', array('subject' => $this, 'response' => $this->Response(), 'request' => $this->Request()))) { $this->Response()->sendResponse(); } Enlight_Application::Instance()->Events()->notify('Enlight_Controller_Front_AfterSendResponse', array('subject' => $this, 'request' => $this->Request())); return 0; }
/** * Set front instance * * @param Enlight_Controller_Front $front * @return Enlight_Controller_Action */ public function setFront(Enlight_Controller_Front $front = null) { if ($front === null) { $front = Enlight_Application::Instance()->Bootstrap()->getResource('Front'); } $this->front = $front; return $this; }