/** * @param \Silex\Application $app * * @return void */ public function register(Application $app) { $this->app = $app; $this->provideFormTypeExtension(); $this->provideFormTypeTemplates(); $app['twig.loader.zed'] = $app->share(function () { $namespaces = Config::get(ApplicationConstants::PROJECT_NAMESPACES); $storeName = Store::getInstance()->getStoreName(); $paths = []; foreach ($namespaces as $namespace) { $paths[] = APPLICATION_SOURCE_DIR . '/' . $namespace . '/Zed/%s' . $storeName . '/Presentation/'; $paths[] = APPLICATION_SOURCE_DIR . '/' . $namespace . '/Zed/%s/Presentation/'; } $paths[] = $this->getConfig()->getBundlesDirectory() . '/%2$s/src/Spryker/Zed/%1$s/Presentation/'; return new Filesystem($paths); }); $app['twig.loader'] = $app->share(function ($app) { return new Twig_Loader_Chain([$app['twig.loader.zed'], $app['twig.loader.filesystem']]); }); $app['twig.options'] = Config::get(ApplicationConstants::ZED_TWIG_OPTIONS); $app['twig.global.variables'] = $app->share(function () { return []; }); $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) use($app) { foreach ($app['twig.global.variables'] as $name => $value) { $twig->addGlobal($name, $value); } return $twig; })); }
/** * @param \Spryker\Zed\Kernel\Container $container * * @return \Spryker\Zed\Kernel\Container */ public function provideBusinessLayerDependencies(Container $container) { $container[self::STORE_CONFIG] = function (Container $container) { return Store::getInstance(); }; return $container; }
/** * @return void */ public function testPluginExpandsCartItemWithExpectedProductData() { $localeName = Store::getInstance()->getCurrentLocale(); $localeTransfer = $this->localeFacade->getLocale($localeName); $taxRateEntity = new SpyTaxRate(); $taxRateEntity->setRate(self::TAX_RATE_PERCENTAGE)->setName(self::TAX_RATE_NAME); $taxSetEntity = new SpyTaxSet(); $taxSetEntity->addSpyTaxRate($taxRateEntity)->setName(self::TAX_SET_NAME); $productAbstractEntity = new SpyProductAbstract(); $productAbstractEntity->setSpyTaxSet($taxSetEntity)->setAttributes('')->setSku(self::SKU_PRODUCT_ABSTRACT); $localizedAttributesEntity = new SpyProductLocalizedAttributes(); $localizedAttributesEntity->setName(self::PRODUCT_CONCRETE_NAME)->setAttributes('')->setFkLocale($localeTransfer->getIdLocale()); $productConcreteEntity = new SpyProduct(); $productConcreteEntity->setSpyProductAbstract($productAbstractEntity)->setAttributes('')->addSpyProductLocalizedAttributes($localizedAttributesEntity)->setSku(self::SKU_PRODUCT_CONCRETE)->save(); $changeTransfer = new CartChangeTransfer(); $itemTransfer = new ItemTransfer(); $itemTransfer->setSku(self::SKU_PRODUCT_CONCRETE); $changeTransfer->addItem($itemTransfer); $this->productCartConnectorFacade->expandItems($changeTransfer); $expandedItemTransfer = $changeTransfer->getItems()[0]; $this->assertEquals(self::SKU_PRODUCT_ABSTRACT, $expandedItemTransfer->getAbstractSku()); $this->assertEquals(self::SKU_PRODUCT_CONCRETE, $expandedItemTransfer->getSku()); $this->assertEquals($productAbstractEntity->getIdProductAbstract(), $expandedItemTransfer->getIdProductAbstract()); $this->assertEquals($productConcreteEntity->getIdProduct(), $expandedItemTransfer->getId()); }
/** * @param \Spryker\Zed\Kernel\Container $container * * @return \Spryker\Zed\Kernel\Container */ protected function addStore(Container $container) { $container[static::STORE] = function () { return Store::getInstance(); }; return $container; }
/** * @return callable */ protected function getFunction() { return function ($currentController) { $html = '<div class="zed:header__environment"><i class="icon-cogs"></i>' . '<span>' . APPLICATION_ENV . '</span>' . '<dl>' . '<dt>Locale:' . '<dd>' . Store::getInstance()->getCurrentLocale() . '<dt>Store:' . '<dd>' . Store::getInstance()->getStoreName() . '<dt>Server:' . '<dd>' . System::getHostName() . '<dt>Controller:' . '<dd>' . $currentController . '</dl></div>'; return $html; }; }
/** * @deprecated Use Store class instead * * @return \Spryker\Shared\Library\Currency\CurrencyInterface */ public static function getDefaultCurrency() { if (!self::$currency) { self::$currency = self::loadCurrencyClass(Store::getInstance()->getCurrencyIsoCode()); } return self::$currency; }
/** * @return void */ protected function setUp() { parent::setUp(); $this->localeFacade = new LocaleFacade(); $this->localeQueryContainer = new LocaleQueryContainer(); $this->availableLocales = Store::getInstance()->getLocales(); $this->localeNames = $this->localeFacade->getAvailableLocales(); }
/** * Defines the prefix for the sequence number which is the public id of an order. * * @return \Generated\Shared\Transfer\SequenceNumberSettingsTransfer */ public function getOrderReferenceDefaults() { $sequenceNumberSettingsTransfer = new SequenceNumberSettingsTransfer(); $sequenceNumberSettingsTransfer->setName(SalesConstants::NAME_ORDER_REFERENCE); $sequenceNumberPrefixParts = []; $sequenceNumberPrefixParts[] = Store::getInstance()->getStoreName(); $sequenceNumberPrefixParts[] = $this->get(SalesConstants::ENVIRONMENT_PREFIX); $prefix = implode($this->getUniqueIdentifierSeparator(), $sequenceNumberPrefixParts) . $this->getUniqueIdentifierSeparator(); $sequenceNumberSettingsTransfer->setPrefix($prefix); return $sequenceNumberSettingsTransfer; }
/** * @return void */ public function setUp() { parent::setUp(); $this->Store = Store::getInstance(); $locales = $this->Store->getLocales(); if (!in_array('de_DE', $locales)) { $this->markTestSkipped('These tests require `de_DE` as part of the current whitelisted locales.'); return; } $this->Store->setCurrentLocale('de_DE'); }
/** * @return void */ public function testIfTransactionIsInIgnoredListMarkIgnoreTransactionShouldBeCalled() { $newRelicApiMock = $this->getNewRelicApiMock(); $newRelicApiMock->expects($this->once())->method('markIgnoreTransaction'); $controllerListener = new ControllerListener($newRelicApiMock, Store::getInstance(), new System(), ['bar/baz']); $request = new Request(); $request->attributes->set('module', 'foo'); $request->attributes->set('controller', 'bar'); $request->attributes->set('action', 'baz'); $controller = function () { }; $filterControllerEvent = new FilterControllerEvent($this->getKernelMock(), $controller, $request, HttpKernelInterface::MASTER_REQUEST); $controllerListener->onKernelController($filterControllerEvent); }
/** * Sets cache control and store information in headers. * * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event A FilterResponseEvent instance * * @return void */ public function onKernelResponse(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $store = Store::getInstance(); $event->getResponse()->headers->set('X-Store', $store->getStoreName()); $event->getResponse()->headers->set('X-Env', APPLICATION_ENV); $event->getResponse()->headers->set('X-Locale', $store->getCurrentLocale()); $event->getResponse()->setPrivate(); $event->getResponse()->setMaxAge(0); $event->getResponse()->headers->addCacheControlDirective('no-cache', true); $event->getResponse()->headers->addCacheControlDirective('no-store', true); $event->getResponse()->headers->addCacheControlDirective('must-revalidate', true); }
/** * @param string $destination * * @throws \LogicException * * @return string */ public function getRouteFromDestination($destination) { if (strpos($destination, '::') !== false) { list($controllerNamespaceName, $actionName) = explode('::', $destination); } elseif (strpos($destination, ':') !== false) { list($serviceName, $actionName) = explode(':', $destination); $controllerNamespaceName = get_class($this->app[$serviceName]); } else { throw new LogicException('Cannot parse destination'); } list($namespace, $application, $bundle, $layer, $controllerName) = explode('\\', $controllerNamespaceName); $filter = new CamelCaseToSeparatorFilter('-'); $bundle = str_replace(Store::getInstance()->getStoreName(), '', $bundle); $controller = $filter->filter(str_replace('Controller', '', $controllerName)); $action = $filter->filter(str_replace('Action', '', $actionName)); return $bundle . '/' . $controller . '/' . $action; }
/** * @return \Generated\Shared\Transfer\PayoneStandardParameterTransfer */ public function getRequestStandardParameter() { $settings = $this->get(PayoneConstants::PAYONE); $standardParameter = new PayoneStandardParameterTransfer(); $standardParameter->setEncoding($settings[PayoneConstants::PAYONE_CREDENTIALS_ENCODING]); $standardParameter->setMid($settings[PayoneConstants::PAYONE_CREDENTIALS_MID]); $standardParameter->setAid($settings[PayoneConstants::PAYONE_CREDENTIALS_AID]); $standardParameter->setPortalId($settings[PayoneConstants::PAYONE_CREDENTIALS_PORTAL_ID]); $standardParameter->setKey($settings[PayoneConstants::PAYONE_CREDENTIALS_KEY]); $standardParameter->setPaymentGatewayUrl($settings[PayoneConstants::PAYONE_PAYMENT_GATEWAY_URL]); $standardParameter->setCurrency(Store::getInstance()->getCurrencyIsoCode()); $standardParameter->setLanguage(Store::getInstance()->getCurrentLanguage()); $standardParameter->setRedirectSuccessUrl($this->getYvesBaseUrl() . $settings[PayoneConstants::PAYONE_REDIRECT_SUCCESS_URL]); $standardParameter->setRedirectBackUrl($this->getYvesBaseUrl() . $settings[PayoneConstants::PAYONE_REDIRECT_BACK_URL]); $standardParameter->setRedirectErrorUrl($this->getYvesBaseUrl() . $settings[PayoneConstants::PAYONE_REDIRECT_ERROR_URL]); return $standardParameter; }
/** * @param \Silex\Application $app * * @return void */ public function boot(Application $app) { $app->before(function (Request $request) { $module = $request->attributes->get('module'); $controller = $request->attributes->get('controller'); $action = $request->attributes->get('action'); $transactionName = $module . '/' . $controller . '/' . $action; $requestUri = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : 'unknown'; $host = isset($_SERVER['COMPUTERNAME']) ? $_SERVER['COMPUTERNAME'] : System::getHostname(); $store = Store::getInstance(); $newRelicApi = new NewRelicApi(); $newRelicApi->setNameOfTransaction($transactionName); $newRelicApi->addCustomParameter('request_uri', $requestUri); $newRelicApi->addCustomParameter('host', $host); $newRelicApi->addCustomParameter('store', $store->getStoreName()); $newRelicApi->addCustomParameter('locale', $store->getCurrentLocale()); }); }
/** * @return void */ public static function initialize() { date_default_timezone_set('UTC'); static::defineEnvironment(); static::defineStore(); static::defineApplication(); static::defineApplicationRootDir(); static::defineApplicationSourceDir(); static::defineApplicationStaticDir(); static::defineApplicationVendorDir(); static::defineApplicationDataDir(); static::initializeErrorHandlerEnvironment(); ini_set('display_errors', Config::get(LibraryConstants::DISPLAY_ERRORS, false)); $store = Store::getInstance(); $locale = current($store->getLocales()); self::initializeLocale($locale); mb_internal_encoding('UTF-8'); mb_regex_encoding('UTF-8'); }
/** * @param string|null $environment * * @return void */ public static function init($environment = null) { if ($environment === null) { $environment = Environment::getInstance()->getEnvironment(); } $storeName = Store::getInstance()->getStoreName(); $config = new \ArrayObject(); /* * e.g. config_default.php */ self::buildConfig('default', $config); /* * e.g. config_default-production.php */ self::buildConfig('default-' . $environment, $config); /* * e.g. config_default_DE.php */ self::buildConfig('default_' . $storeName, $config); /* * e.g. config_default-production_DE.php */ self::buildConfig('default-' . $environment . '_' . $storeName, $config); /* * e.g. config_local_test.php */ self::buildConfig('local_test', $config); /* * e.g. config_local.php */ self::buildConfig('local', $config); /* * e.g. config_local_DE.php */ self::buildConfig('local_' . $storeName, $config); /* * e.g. config_propel.php */ self::buildConfig('propel', $config); self::$config = $config; }
/** * @param string $filename * * @throws \ErrorException * * @return string */ public static function getAbsoluteProductImageUrl($filename) { $urlDomain = self::getStaticMediaUrl(); if ($filename === '') { $applicationName = APPLICATION; switch ($applicationName) { case 'ZED': return self::getSchema() . Config::get(LibraryConstants::HOST_ZED_GUI) . self::PLACEHOLDER_PRODUCT_ZED; case 'YVES': return self::getSchema() . Config::get(LibraryConstants::HOST_YVES) . self::PLACEHOLDER_PRODUCT_YVES; default: throw new ErrorException('Invalid Application name'); } } $urlKey = $filename; /* ONLY FOR CLOUD HOSTING SETUP USED */ if (Cloud::isCloudStorageCdnEnabled()) { return self::getAbsoluteProductImageUrlForCloudUsage($urlKey); } return self::getSchema() . implode('/', [$urlDomain, Store::getInstance()->getStoreName(), Config::get(LibraryConstants::PRODUCT_IMAGE_IMAGE_URL_PREFIX), $urlKey]); }
/** * @return string */ protected function getPrefix() { return sprintf('%s-%s-', Store::getInstance()->getStoreName(), $this->get(SequenceNumberConstants::ENVIRONMENT_PREFIX)); }
<?php use Spryker\Shared\Kernel\Store; use Spryker\Shared\Propel\PropelConstants; use Spryker\Zed\Propel\Business\Builder\ObjectBuilder; use Spryker\Zed\Propel\Business\Builder\QueryBuilder; use Spryker\Zed\Propel\PropelConfig; $config[PropelConstants::ZED_DB_ENGINE_MYSQL] = PropelConfig::DB_ENGINE_MYSQL; $config[PropelConstants::ZED_DB_ENGINE_PGSQL] = PropelConfig::DB_ENGINE_PGSQL; $config[PropelConstants::ZED_DB_SUPPORTED_ENGINES] = [PropelConfig::DB_ENGINE_MYSQL => 'MySql', PropelConfig::DB_ENGINE_PGSQL => 'PostgreSql']; $config[PropelConstants::ZED_DB_USERNAME] = getenv(PropelConstants::ZED_DB_USERNAME) ?: 'development'; $config[PropelConstants::ZED_DB_PASSWORD] = getenv(PropelConstants::ZED_DB_PASSWORD) ?: 'mate20mg'; $config[PropelConstants::ZED_DB_DATABASE] = getenv(PropelConstants::ZED_DB_DATABASE) ?: 'DE_test_zed'; $config[PropelConstants::ZED_DB_HOST] = getenv(PropelConstants::ZED_DB_HOST) ?: '127.0.0.1'; $config[PropelConstants::USE_SUDO_TO_MANAGE_DATABASE] = false; $config[PropelConstants::ZED_DB_PORT] = getenv(PropelConstants::ZED_DB_PORT) ?: 5432; $config[PropelConstants::ZED_DB_ENGINE] = getenv(PropelConstants::ZED_DB_ENGINE) ?: $config[PropelConstants::ZED_DB_ENGINE_PGSQL]; $currentStore = Store::getInstance()->getStoreName(); $dsn = sprintf('%s:host=%s;port=%d;dbname=%s', $config[PropelConstants::ZED_DB_ENGINE], $config[PropelConstants::ZED_DB_HOST], $config[PropelConstants::ZED_DB_PORT], $config[PropelConstants::ZED_DB_DATABASE]); $connections = ['pgsql' => ['adapter' => PropelConfig::DB_ENGINE_PGSQL, 'dsn' => $dsn, 'user' => $config[PropelConstants::ZED_DB_USERNAME], 'password' => $config[PropelConstants::ZED_DB_PASSWORD], 'settings' => []], 'mysql' => ['adapter' => PropelConfig::DB_ENGINE_MYSQL, 'dsn' => $dsn, 'user' => $config[PropelConstants::ZED_DB_USERNAME], 'password' => $config[PropelConstants::ZED_DB_PASSWORD], 'settings' => ['charset' => 'utf8', 'queries' => ['utf8' => 'SET NAMES utf8 COLLATE utf8_unicode_ci, COLLATION_CONNECTION = utf8_unicode_ci, COLLATION_DATABASE = utf8_unicode_ci, COLLATION_SERVER = utf8_unicode_ci']]]]; $engine = $config[PropelConstants::ZED_DB_ENGINE]; $config[PropelConstants::PROPEL] = ['database' => ['connections' => ['default' => $connections[$engine], 'zed' => $connections[$engine]]], 'runtime' => ['defaultConnection' => 'default', 'connections' => ['default', 'zed']], 'generator' => ['defaultConnection' => 'default', 'connections' => ['default', 'zed'], 'objectModel' => ['defaultKeyType' => 'fieldName', 'builders' => ['object' => ObjectBuilder::class, 'query' => QueryBuilder::class]]], 'paths' => ['phpDir' => APPLICATION_ROOT_DIR, 'sqlDir' => APPLICATION_ROOT_DIR . '/src/Orm/Propel/' . $currentStore . '/Sql', 'migrationDir' => APPLICATION_ROOT_DIR . '/src/Orm/Propel/' . $currentStore . '/Migration_' . $config[PropelConstants::ZED_DB_ENGINE], 'schemaDir' => APPLICATION_ROOT_DIR . '/src/Orm/Propel/' . $currentStore . '/Schema', 'phpConfDir' => APPLICATION_ROOT_DIR . '/src/Orm/Propel/' . $currentStore . '/Config']];
/** * @return \Spryker\Zed\Search\Business\Model\Elasticsearch\Definition\JsonIndexDefinitionLoader */ protected function createJsonIndexDefinitionLoader() { return new JsonIndexDefinitionLoader($this->getConfig()->getJsonIndexDefinitionDirectories(), $this->createJsonIndexDefinitionMerger(), Store::getInstance()->getAllowedStores()); }
/** * @param string $key * * @return string */ protected static function prependStoreName($key) { $storeName = Store::getInstance()->getStoreName(); return $storeName . self::KEY_SEPARATOR . $key; }
/** * @return string */ protected function getBucketName() { $storeName = Store::getInstance()->getStoreName(); $environment = Environment::getInstance()->getEnvironment(); return $storeName . '_' . $environment . '_' . self::BUCKET_NAME_POSTFIX; }
/** * @return \Generated\Shared\Transfer\LocalizedAttributesTransfer */ protected function createLocalizedAttributesTransfer() { $localeName = Store::getInstance()->getCurrentLocale(); $localeTransfer = $this->localeFacade->getLocale($localeName); $localizedAttributesTransfer = new LocalizedAttributesTransfer(); $localizedAttributesTransfer->setLocale($localeTransfer)->setName('Foo'); return $localizedAttributesTransfer; }
/** * @param mixed $data * @param string $localeName * * @return array */ protected function getKeyParts($data, $localeName) { return [Store::getInstance()->getStoreName(), $localeName, $this->getBundleName(), $this->buildKey($data)]; }
/** * @return array */ public function getAllowedStores() { return Store::getInstance()->getAllowedStores(); }
/** * @deprecated See \Spryker\Client\Catalog\Model\Catalog for more info. * * @return \Spryker\Client\Catalog\Model\Catalog */ public function createCatalogModel() { return new ModelCatalog($this->createProductKeyBuilder(), $this->getStorageClient(), Store::getInstance()->getCurrentLocale()); }
/** * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return array */ public function exportStorage(OutputInterface $output) { $storeCollection = Store::getInstance()->getAllowedStores(); $results = []; foreach ($storeCollection as $storeName) { $output->writeln(''); $output->writeln('<fg=yellow>----------------------------------------</fg=yellow>'); $output->writeln(sprintf('<fg=yellow>Exporting Store:</fg=yellow> <fg=white>%s</fg=white>', $storeName)); $output->writeln(''); $localeCollection = Store::getInstance()->getLocalesPerStore($storeName); foreach ($localeCollection as $locale => $localeCode) { $localeTransfer = $this->localeFacade->getLocale($localeCode); $results[$storeName . '@' . $localeCode] = $this->exportStorageByLocale($localeTransfer, $output); } } return $results; }
/** * @param string $sessionId * @param string $sessionData * * @return bool */ public function write($sessionId, $sessionData) { $key = $this->keyPrefix . $sessionId; if (strlen($sessionData) < 1) { return false; } $startTime = microtime(true); $environment = Environment::getInstance()->getEnvironment(); $data = json_encode($sessionData); $expireTimestamp = time() + $this->lifetime; $expires = date('Y-m-d H:i:s', $expireTimestamp); $storeName = Store::getInstance()->getStoreName(); $timestamp = date('Y-m-d H:i:s', time()); $query = 'REPLACE INTO session (session.key, session.value, session.store, session.environment, session.expires, session.updated_at) VALUES (?,?,?,?,?,?)'; $statement = $this->connection->prepare($query); $result = $statement->execute([$key, $data, $storeName, $environment, $expires, $timestamp]); $this->newRelicApi->addCustomMetric(self::METRIC_SESSION_WRITE_TIME, microtime(true) - $startTime); return $result; }
/** * @api * * @return string */ public function getCurrentLocale() { return Store::getInstance()->getCurrentLocale(); }
/** * @param bool $storeSpecific (stored in store specific sub.folder?) * @param bool $isSharedBetweenHosts (weather to store in 'static' directory in shared NFS) * * @return string */ protected static function getBaseDataPath($storeSpecific = false, $isSharedBetweenHosts = true) { $path = APPLICATION_ROOT_DIR . DIRECTORY_SEPARATOR . self::PATH_DATA; if ($isSharedBetweenHosts) { $path .= DIRECTORY_SEPARATOR . self::PATH_SHARED; } if ($storeSpecific) { $path .= DIRECTORY_SEPARATOR . Store::getInstance()->getStoreName(); } return $path; }