getRequest()->setIsSecure(true); } stPluginHelper::addRouting('stWebApiProductUrlLangFrontend', '/:lang/:url.html', 'stProduct', 'show', null, array(), array('lang' => '[a-z]{2,2}')); stPluginHelper::addRouting('stWebApiProductUrlFrontend', '/:url.html', 'stProduct', 'show', null); stPluginHelper::addRouting('stWebApiCategoryUrlFrontend', '/category/:url', 'stProduct', 'list'); stPluginHelper::addRouting('stWebApiCategoryUrlLangFrontend', '/category/:lang/:url', 'stProduct', 'list', null, array(), array('lang' => '[a-z]{2,2}')); stPluginHelper::addRouting('stWebApiProducerUrlFrontend', '/manufacturer/:url', 'stProduct', 'producerList'); stPluginHelper::addRouting('stWebApiProducerUrlLangFrontend', '/manufacturer/:lang/:url', 'stProduct', 'producerList', null, array(), array('lang' => '[a-z]{2,2}')); $this->__setCulture(stLanguage::getOptLanguage()); } /** * Zwraca przetłumaczony tekst * * @param string $message * @param array $args * @param null|string $catalogue * @return mixed */ public static function translate(string $text, array $args = [], ?string $catalogue = null): string { return sfContext::getInstance()->getI18n()->__($text, $args, null !== $catalogue ? $catalogue : 'stWebApiBackend'); } /** * Wyrzuca wyjątek z komunikatem błędu * * @param string $code Kod błędu * @param string $errorMsg Komunikat błędu * @param array $i18nArgs Dodatkowe argumenty komunikatu * @param null|string $i18nCatalogue Katalog tłumaczeń * @return void * @throws SoapFault */ public function throwSoapFault(string $code, string $errorMsg, array $i18nArgs = [], ?string $i18nCatalogue = null): void { throw new SoapFault($code, self::translate($errorMsg, $i18nArgs, $i18nCatalogue), null); } public function __(string $text, array $args = [], ?string $catalogue = null): string { return self::translate($text, $args, $catalogue); } public function __setCulture($culture) { if ($culture == 'en') { $culture = 'en_US'; } elseif ($culture == 'pl') { $culture = 'pl_PL'; } $this->_culture = $culture; sfContext::getInstance()->getRequest()->setHostByCulture($culture); } public function __getCulture() { return $this->_culture ? $this->_culture : stLanguage::getOptLanguage(); } /** * @param Product $product * @return false|string */ public function __getProductUrl(Product $product) { return st_url_for(array('module' => 'stProduct', 'action' => 'show', 'url' => $product->getUrl()), true, 'frontend', null, $product->getCulture()); } /** * @param Category $category * @return false|string */ public function __getCategoryUrl(Category $category) { return st_url_for(array('module' => 'stProduct', 'action' => 'list', 'url' => $category->getUrl()), true, 'frontend', null, $category->getCulture()); } /** * @param Producer $producer * @return false|string */ public function __getProducerUrl(Producer $producer) { return st_url_for(array('module' => 'stProduct', 'action' => 'producerList', 'url' => $producer->getUrl()), true, 'frontend', null, $producer->getCulture()); } protected function validateArrayOfInteger($values, string $fieldPath) { if (!is_array($values)) { self::throwSoapFault('3', WEBAPI_VALIDATE_ERROR, ['%s' => $fieldPath]); } foreach ($values as $index => $value) { if (!is_numeric($value)) { self::throwSoapFault('3', WEBAPI_VALIDATE_ERROR, ['%s' => $fieldPath . '['.$index.']']); } } } protected function validateArrayOfString($values, string $fieldPath) { if (!is_array($values)) { self::throwSoapFault('3', WEBAPI_VALIDATE_ERROR, ['%s' => $fieldPath]); } foreach ($values as $index => $value) { if (!is_string($value)) { self::throwSoapFault('3', WEBAPI_VALIDATE_ERROR, ['%s' => $fieldPath . '['.$index.']']); } } } protected function validateArrayOfDouble($values, string $fieldPath) { if (!is_array($values)) { self::throwSoapFault('3', WEBAPI_VALIDATE_ERROR, ['%s' => $fieldPath]); } foreach ($values as $index => $value) { if (!is_numeric($value)) { self::throwSoapFault('3', WEBAPI_VALIDATE_ERROR, ['%s' => $fieldPath . '['.$index.']']); } } } }