예제 #1
0
 /**
  * Shopware\EventListener: Enlight_Controller_Front_RouteShutdown
  *
  * @param \Enlight_Controller_EventArgs $args
  */
 public function registerBackendTheme(\Enlight_Controller_EventArgs $args)
 {
     if ($args->getRequest()->getModuleName() != 'backend') {
         return;
     }
     $directory = $this->container->get('theme_path_resolver')->getExtJsThemeDirectory();
     $this->container->get('template')->setTemplateDir(array('backend' => $directory, 'include_dir' => '.'));
 }
예제 #2
0
 /**
  * @param Container                $container
  * @param \Shopware_Components_Config   $config
  * @param array                         $options
  * @return \Enlight_Components_Mail|null
  */
 public function factory(Container $container, \Shopware_Components_Config $config, array $options)
 {
     if (!$container->load('MailTransport')) {
         return null;
     }
     if (isset($options['charset'])) {
         $defaultCharSet = $options['charset'];
     } elseif (!empty($config->CharSet)) {
         $defaultCharSet = $config->CharSet;
     } else {
         $defaultCharSet = null;
     }
     $mail = new \Enlight_Components_Mail($defaultCharSet);
     return $mail;
 }
예제 #3
0
 /**
  * Returns cache information
  *
  * @param string $dir
  * @return array
  */
 public function getDirectoryInfo($dir)
 {
     $docRoot = $this->container->getParameter('kernel.root_dir') . '/';
     $info = array();
     $info['dir'] = str_replace($docRoot, '', $dir);
     $info['dir'] = str_replace(DIRECTORY_SEPARATOR, '/', $info['dir']);
     $info['dir'] = rtrim($info['dir'], '/') . '/';
     if (!file_exists($dir) || !is_dir($dir)) {
         $info['message'] = 'Cache dir not exists';
         return $info;
     }
     if (!is_readable($dir)) {
         $info['message'] = 'Cache dir is not readable';
         return $info;
     }
     if (!is_writable($dir)) {
         $info['message'] = 'Cache dir is not writable';
     }
     $info['size'] = (double) 0;
     $info['files'] = 0;
     $dirIterator = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
     $iterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::LEAVES_ONLY);
     /** @var $entry \SplFileInfo */
     foreach ($iterator as $entry) {
         if ($entry->getFileName() === '.gitkeep') {
             continue;
         }
         $info['size'] += $entry->getSize();
         $info['files']++;
     }
     $info['size'] = $this->encodeSize($info['size']);
     $info['freeSpace'] = disk_free_space($dir);
     $info['freeSpace'] = $this->encodeSize($info['freeSpace']);
     return $info;
 }
예제 #4
0
 /**
  * @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;
 }
예제 #5
0
 /**
  * Generates a mediaUrl based on the request or router
  *
  * @return string
  * @throws \Exception
  */
 private function createFallbackMediaUrl()
 {
     $request = $this->container->get('front')->Request();
     if ($request && $request->getHttpHost()) {
         return ($request->isSecure() ? 'https' : 'http') . '://' . $request->getHttpHost() . $request->getBasePath() . "/";
     } else {
         return $this->container->get('front')->Router()->assemble(['controller' => 'index', 'module' => 'frontend']);
     }
 }
 /**
  * Listener method of the Enlight_Controller_Front_DispatchLoopShutdown event.
  * On Dispatch Shutdown collects results and dumps to log component.
  *
  * @param \Enlight_Event_EventArgs $args
  */
 public function onDispatchLoopShutdown(\Enlight_Event_EventArgs $args)
 {
     /** @var \Enlight_Controller_Request_Request $request */
     $request = $args->getSubject()->Request();
     /** @var Clockwork $clockwork */
     $clockwork = $this->container->get('shopwareclockwork.clockwork');
     /** @var \Enlight_Controller_Response_ResponseHttp $response */
     $response = $args->getResponse();
     $response->setHeader("X-Clockwork-Id", $clockwork->getRequest()->id);
     $response->setHeader("X-Clockwork-Version", $clockwork::VERSION);
     $response->setHeader("X-Clockwork-Path", '/Clockwork/index/id/');
     $shopwareDataSource = $this->container->get('shopwareclockwork.datasource');
     $shopwareDataSource->setBaseInfo($request);
     $clockwork->addDataSource(new PhpDataSource());
     $clockwork->addDataSource($shopwareDataSource);
     $clockwork->resolveRequest();
     $clockwork->storeRequest();
 }
예제 #7
0
 /**
  * Collects third party adapters
  *
  * @param array $config
  * @return AdapterInterface
  * @throws \Enlight_Event_Exception
  * @throws \Exception
  */
 private function collectAdapterByType($config)
 {
     $adapters = new ArrayCollection();
     $adapters = $this->container->get('events')->collect('Shopware_Collect_MediaAdapter_' . $config['type'], $adapters, ['config' => $config]);
     $adapter = $adapters->first();
     if (!$adapter) {
         throw new \Exception("CDN Adapter '" . $config['type'] . "' not found.");
     }
     return $adapter;
 }
예제 #8
0
 /**
  * Live migration to fill width/height
  *
  * @param LifecycleEventArgs $eventArgs
  * @throws \Exception
  */
 private function migrateMeta(LifecycleEventArgs $eventArgs)
 {
     $media = $eventArgs->getEntity();
     if (!$media instanceof Media) {
         return;
     }
     if ($media->getType() !== Media::TYPE_IMAGE) {
         return;
     }
     $mediaService = $this->container->get('shopware_media.media_service');
     if ((!$media->getHeight() || !$media->getWidth()) && $mediaService->has($media->getPath())) {
         list($width, $height) = getimagesizefromstring($mediaService->read($media->getPath()));
         if ($media->getId()) {
             $eventArgs->getEntityManager()->getConnection()->executeUpdate('UPDATE s_media SET width = :width, height = :height WHERE id = :id', [':width' => $width, ':height' => $height, ':id' => $media->getId()]);
         }
         $media->setWidth($width);
         $media->setHeight($height);
     }
 }
예제 #9
0
 /**
  * Collect mails
  * @param \Enlight_Event_EventArgs $args
  */
 public function onSendMails(\Enlight_Event_EventArgs $args)
 {
     /** @var \Enlight_Components_Mail $mail */
     $mail = $args->get('mail');
     $context = $this->container->get('templatemail')->getStringCompiler()->getContext();
     /**
      * Remove some objects
      */
     unset($context['sConfig']);
     $this->mails[] = ['from' => $mail->getFrom(), 'fromName' => $mail->getFromName(), 'to' => $mail->getTo(), 'subject' => $mail->getSubject(), 'bodyPlain' => $mail->getPlainBodyText(), 'bodyHtml' => $mail->getPlainBody(), 'context' => $context];
 }
예제 #10
0
 /**
  * @param \Enlight_Event_EventArgs $args
  * @throws \Exception
  */
 public function onDispatch(\Enlight_Event_EventArgs $args)
 {
     /**@var $controller \Enlight_Controller_Action*/
     $controller = $args->get('subject');
     if (!$controller->View()) {
         return;
     }
     /**@var $shop Shop*/
     $shop = $this->container->get('shop');
     if ($shop->getTemplate()->getVersion() < 3) {
         return;
     }
     $templateManager = $this->container->get('template');
     $themeSettings = $templateManager->getTemplateVars('theme');
     if (!empty($themeSettings)) {
         return;
     }
     $inheritance = $this->container->get('theme_inheritance');
     $config = $inheritance->buildConfig($shop->getTemplate(), $shop, false);
     $templateManager->addPluginsDir($inheritance->getSmartyDirectories($shop->getTemplate()));
     $templateManager->assign('theme', $config);
 }
예제 #11
0
 /**
  * Initializes the service container.
  *
  * The cached version of the service container is used when fresh, otherwise the
  * container is built.
  */
 protected function initializeContainer()
 {
     $class = $this->getContainerClass();
     $cache = new ConfigCache($this->config['hook']['proxyDir'] . '/' . $class . '.php', true);
     if (!$cache->isFresh()) {
         $container = $this->buildContainer();
         $container->compile();
         $this->dumpContainer($cache, $container, $class, 'Shopware\\Components\\DependencyInjection\\Container');
     }
     require_once $cache->getPath();
     $this->container = new $class();
     $this->container->set('kernel', $this);
 }
예제 #12
0
 protected function getCategoryTree($id, $mainId)
 {
     $sql = '
         SELECT `id`, `description`, `parent`
         FROM `s_categories`
         WHERE `id` = ?
     ';
     $cat = $this->container->get('db')->fetchRow($sql, array($id));
     if (empty($cat['id']) || $id == $cat['parent'] || $id == $mainId) {
         return array();
     } else {
         $cats = $this->getCategoryTree($cat['parent'], $mainId);
         $cats[$id] = $cat;
         return $cats;
     }
 }
예제 #13
0
 /**
  * @return string
  */
 private function buildBaseUrl()
 {
     /** @var $config \Shopware_Components_Config */
     $config = $this->container->get('config');
     $request = null;
     if ($this->container->initialized('front')) {
         /** @var $front \Enlight_Controller_Front */
         $front = $this->container->get('front');
         $request = $front->Request();
     }
     if ($request !== null) {
         $baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
     } else {
         $baseUrl = 'http://' . $config->get('basePath');
     }
     return $baseUrl;
 }
예제 #14
0
 /**
  * This helper method will reload the EntityManager.
  * This is useful if the EntityManager was closed due to an error on the
  * PDO connection.
  */
 protected function resetEntityManager()
 {
     $this->getContainer()->reset('models')->reset('db_connection')->load('models');
     $this->getContainer()->load('db_connection');
     $this->setManager($this->container->get('models'));
 }
예제 #15
0
 public function registerFacetHandler()
 {
     return new EsdFacetHandler($this->container->get('shopware_searchdbal.dbal_query_builder_factory'), $this->container->get('snippets'));
 }
예제 #16
0
 /**
  * Runs the garbage collector
  *
  * @return bool
  * @throws \Exception
  */
 public function runCronjob()
 {
     $garbageCollector = $this->container->get('shopware_media.garbage_collector');
     $garbageCollector->run();
     return true;
 }
예제 #17
0
 public function addLessFiles()
 {
     $less = new LessDefinition([], [$this->container->getParameter('shyim_profiler.plugin_dir') . '/Resources/views/frontend/_public/src/less/all.less'], __DIR__);
     return new ArrayCollection([$less]);
 }
예제 #18
-1
 /**
  * Sets the Container.
  *
  * @param Container $container
  */
 public function setContainer(Container $container = null)
 {
     if ($container) {
         $this->request = $container->get('front')->Request();
         $this->cacheManager = $container->get('shopware.cache_manager');
     }
 }
예제 #19
-1
 /**
  * Loads the Zend resource and initials the Enlight_Controller_Front class.
  * After the front resource is loaded, the controller path is added to the
  * front dispatcher. After the controller path is set to the dispatcher,
  * the plugin namespace of the front resource is set.
  *
  * @param Container $container
  * @param \Shopware_Bootstrap $bootstrap
  * @param \Enlight_Event_EventManager $eventManager
  * @param array $options
  * @throws \Exception
  * @return \Enlight_Controller_Front
  */
 public function factory(Container $container, \Shopware_Bootstrap $bootstrap, \Enlight_Event_EventManager $eventManager, array $options)
 {
     /** @var $front \Enlight_Controller_Front */
     $front = \Enlight_Class::Instance('Enlight_Controller_Front', array($eventManager));
     $front->Dispatcher()->addModuleDirectory(Shopware()->AppPath('Controllers'));
     $front->setParams($options);
     /** @var $plugins  \Enlight_Plugin_PluginManager */
     $plugins = $container->get('Plugins');
     $plugins->registerNamespace($front->Plugins());
     $front->setParam('bootstrap', $bootstrap);
     if (!empty($options['throwExceptions'])) {
         $front->throwExceptions((bool) $options['throwExceptions']);
     }
     try {
         $container->load('Cache');
         $container->load('Db');
         $container->load('Plugins');
     } catch (\Exception $e) {
         if ($front->throwExceptions()) {
             throw $e;
         }
         $front->Response()->setException($e);
     }
     return $front;
 }
예제 #20
-1
 /**
  * @param Container $container
  * @return \Enlight_Components_Session_Namespace
  */
 public function factory(Container $container)
 {
     $sessionOptions = Shopware()->getOption('session', array());
     if (!empty($sessionOptions['unitTestEnabled'])) {
         \Enlight_Components_Session::$_unitTestEnabled = true;
     }
     unset($sessionOptions['unitTestEnabled']);
     if (\Enlight_Components_Session::isStarted()) {
         \Enlight_Components_Session::writeClose();
     }
     /** @var $shop \Shopware\Models\Shop\Shop */
     $shop = $container->get('Shop');
     $name = 'session-' . $shop->getId();
     $sessionOptions['name'] = $name;
     if (!isset($sessionOptions['save_handler']) || $sessionOptions['save_handler'] == 'db') {
         $config_save_handler = array('db' => $container->get('Db'), 'name' => 's_core_sessions', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'expiry');
         \Enlight_Components_Session::setSaveHandler(new \Enlight_Components_Session_SaveHandler_DbTable($config_save_handler));
         unset($sessionOptions['save_handler']);
     }
     \Enlight_Components_Session::start($sessionOptions);
     $container->set('SessionID', \Enlight_Components_Session::getId());
     $namespace = new \Enlight_Components_Session_Namespace('Shopware');
     $namespace->offsetSet('sessionId', \Enlight_Components_Session::getId());
     return $namespace;
 }
예제 #21
-1
 /**
  * @return DefaultSortRequestHandler
  */
 private function getSortRequestHandler()
 {
     if (!$this->sortRequestHandler) {
         $this->sortRequestHandler = new DefaultSortRequestHandler($this->container->get('swag_default_sort.database_adapter'), $this->container->get('swag_default_sort.rule_vo_hydrator'));
     }
     return $this->sortRequestHandler;
 }
예제 #22
-1
 /**
  * @param Container    $container
  * @param \Zend_Locale      $locale
  *
  * @return \Zend_Currency
  */
 public function factory(Container $container, \Zend_Locale $locale)
 {
     $currency = 'EUR';
     if ($container->has('Shop')) {
         $currency = $container->get('Shop')->getCurrency()->getCurrency();
     }
     return new \Zend_Currency($currency, $locale);
 }
예제 #23
-1
 /**
  * @param Container $container
  * @return \Zend_Locale
  */
 public function factory(Container $container)
 {
     $locale = 'de_DE';
     if ($container->has('Shop')) {
         $locale = $container->get('Shop')->getLocale()->getLocale();
     }
     return new \Zend_Locale($locale);
 }
예제 #24
-1
 /**
  * @param sArticles $articleModule
  * @param Container $container
  */
 public function __construct(sArticles $articleModule, Container $container)
 {
     $this->articleModule = $articleModule;
     $this->systemModule = $articleModule->sSYSTEM;
     $this->db = $container->get('db');
     $this->config = $container->get('config');
     $this->session = $container->get('session');
     $this->contextService = $container->get('shopware_storefront.context_service');
 }
예제 #25
-1
 public function onFilterCollectors(\Enlight_Event_EventArgs $arguments)
 {
     $collectors = $arguments->getReturn();
     $utils = $arguments->get('utils');
     foreach ($collectors as $key => $collector) {
         if ($collector instanceof EventCollector) {
             $collectors[$key] = new ClockworkEventCollector($arguments->get('eventManager'), $utils);
         } elseif ($collector instanceof TemplateCollector) {
             $collectors[$key] = new ClockworkTemplateCollector($this->container->get('template'), $utils, $this->container->get('kernel')->getRootDir());
         }
     }
     return $collectors;
 }
 /**
  * @param $containers
  * @param $orderData
  * @return mixed
  * @throws Exception
  */
 public function getPayPalInvoiceContentInfo($containers, $orderData)
 {
     $footer = $containers['Paypal_Content_Info'];
     $translationComp = new Shopware_Components_Translation();
     $translation = $translationComp->read($orderData['_order']['language'], 'documents', 1);
     $query = "SELECT * FROM s_core_documents_box WHERE id = ?";
     /** @var Enlight_Components_Db_Adapter_Pdo_Mysql $databaseConnection */
     $databaseConnection = $this->container->get('db');
     $rawFooter = $databaseConnection->fetchAssoc($query, array($footer['id']));
     if (!empty($translation[1]["Paypal_Content_Info_Value"])) {
         $rawFooter["value"] = $translation[1]["Paypal_Content_Info_Value"];
     }
     return $rawFooter[$footer['id']];
 }
예제 #27
-1
 private function processQueue()
 {
     if (empty($this->queue)) {
         return;
     }
     $this->container->get('shopware_elastic_search.backlog_processor')->add($this->queue);
     $this->queue = [];
 }
예제 #28
-1
 /**
  * Get and setup ProductService Component
  *
  * This method also does the setup like autoloading.
  *
  * @return \Shopware_StoreApi_Core_Service_Product
  */
 private function getProductService()
 {
     /** @var $communityStore CommunityStore */
     $communityStore = $this->container->get('CommunityStore');
     $storeApi = $communityStore->getApi();
     $productService = $storeApi->getProductService();
     return $productService;
 }
예제 #29
-1
 /**
  * @param Container $container
  * @return \Shopware_Components_TemplateMail
  */
 public function factory(Container $container)
 {
     $container->load('MailTransport');
     $stringCompiler = new \Shopware_Components_StringCompiler($container->get('Template'));
     $mailer = new \Shopware_Components_TemplateMail();
     if ($container->initialized('Shop')) {
         $mailer->setShop($container->get('Shop'));
     }
     $mailer->setModelManager($container->get('Models'));
     $mailer->setStringCompiler($stringCompiler);
     return $mailer;
 }
예제 #30
-1
 /**
  * @param Container $container
  * @param EnlightEventManager $eventManager
  * @return \Shopware\Components\Routing\RouterInterface
  * @throws \Exception
  */
 public function factory(Container $container, EnlightEventManager $eventManager)
 {
     $queryAliasMapper = $container->get('query_alias_mapper');
     $matchers = [new Matchers\RewriteMatcher($container->get('dbal_connection'), $queryAliasMapper), new Matchers\EventMatcher($eventManager), new Matchers\DefaultMatcher($container->get('dispatcher'))];
     $generators = [new Generators\RewriteGenerator($container->get('dbal_connection'), $queryAliasMapper), new Generators\DefaultGenerator($container->get('dispatcher'))];
     $preFilters = [new GeneratorFilters\DefaultPreFilter(), new GeneratorFilters\FrontendPreFilter()];
     $postFilters = [new GeneratorFilters\FrontendPostFilter(), new GeneratorFilters\DefaultPostFilter()];
     $router = new \Shopware\Components\Routing\Router(Context::createEmpty(), $matchers, $generators, $preFilters, $postFilters);
     /** Still better than @see \Shopware\Models\Shop\Shop::registerResources */
     $eventManager->addListener('Enlight_Bootstrap_AfterRegisterResource_Shop', array($this, 'onAfterRegisterShop'), -100);
     $eventManager->addListener('Enlight_Controller_Front_PreDispatch', array($this, 'onPreDispatch'), -100);
     return $router;
 }