Пример #1
0
 protected function trans($id, $parameters = [])
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters);
 }
Пример #2
0
 protected function trans($id, $parameters = [], $locale = null)
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, self::MESSAGE_DOMAIN, $locale);
 }
Пример #3
0
 protected function trans($id, $parameters = [])
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, StockAlert::MESSAGE_DOMAIN);
 }
Пример #4
0
 protected function trans($id, $locale, $parameters = [])
 {
     if ($this->translator === null) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, self::MODULE_DOMAIN, $locale);
 }
Пример #5
0
 public function checkOrders(array $values)
 {
     foreach ($this->getOrder() as $order) {
         if (!array_key_exists($order, $values)) {
             throw new \ErrorException($this->translator->trans("The column %column that you want to sort doesn't exist", ["%column" => $order]));
         }
     }
 }
Пример #6
0
 /**
  * Process the count function: executes a loop and return the number of items found
  *
  * @param array $params parameters array
  * @param \Smarty_Internal_Template $template
  *
  * @return int                       the item count
  * @throws \InvalidArgumentException if a parameter is missing
  *
  */
 public function hasFlashMessage($params, $template)
 {
     $type = $this->getParam($params, 'type', null);
     if (null == $type) {
         throw new \InvalidArgumentException($this->translator->trans("Missing 'type' parameter in {hasflash} function arguments"));
     }
     return $this->getSession()->getFlashBag()->has($type);
 }
Пример #7
0
 /**
  * Get operator translation
  *
  * @param Translator $translator Provide necessary value from Thelia
  * @param string     $operator   Operator const
  *
  * @return string
  */
 public static function getI18n(Translator $translator, $operator)
 {
     $ret = $operator;
     switch ($operator) {
         case self::INFERIOR:
             $ret = $translator->trans('Less than', []);
             break;
         case self::INFERIOR_OR_EQUAL:
             $ret = $translator->trans('Less than or equals', []);
             break;
         case self::EQUAL:
             $ret = $translator->trans('Equal to', []);
             break;
         case self::SUPERIOR_OR_EQUAL:
             $ret = $translator->trans('Greater than or equals', []);
             break;
         case self::SUPERIOR:
             $ret = $translator->trans('Greater than', []);
             break;
         case self::DIFFERENT:
             $ret = $translator->trans('Not equal to', []);
             break;
         case self::IN:
             $ret = $translator->trans('In', []);
             break;
         case self::OUT:
             $ret = $translator->trans('Not in', []);
             break;
         default:
     }
     return $ret;
 }
Пример #8
0
 protected function checkMandatoryColumns(array $row)
 {
     $mandatoryColumns = $this->getMandatoryColumns();
     sort($mandatoryColumns);
     $diff = [];
     foreach ($mandatoryColumns as $name) {
         if (!isset($row[$name]) || empty($row[$name])) {
             $diff[] = $name;
         }
     }
     if (!empty($diff)) {
         throw new \UnexpectedValueException($this->translator->trans("The following columns are missing: %columns", ["%columns" => implode(", ", $diff)]));
     }
 }
Пример #9
0
 /**
  * Process translate function
  *
  * @param  array                     $params
  * @param  \Smarty_Internal_Template $smarty
  * @return string
  */
 public function translate($params, &$smarty)
 {
     // All parameters other than 'l' and 'd' and 'js' are supposed to be variables. Build an array of var => value pairs
     // and pass it to the translator
     $vars = array();
     foreach ($params as $name => $value) {
         if (!in_array($name, $this->protectedParams)) {
             $vars["%{$name}"] = $value;
         }
     }
     $str = $this->translator->trans($this->getParam($params, 'l'), $vars, $this->getParam($params, 'd', $this->defaultTranslationDomain), $this->getParam($params, 'locale', $this->defaultLocale), $this->getBoolean($this->getParam($params, 'default', true), true), $this->getBoolean($this->getParam($params, 'fallback', true), true));
     if ($this->getParam($params, 'js', 0)) {
         $str = preg_replace("/(['\"])/", "\\\\\$1", $str);
     }
     return $str;
 }
Пример #10
0
 /**
  * @param  string $environment
  * @return $this
  *
  * Sets the execution environment of the Kernel,
  * used to know which cache is used.
  */
 public function setEnvironment($environment)
 {
     if (empty($environment)) {
         throw new \ErrorException($this->translator->trans("You must define an environment when you use an archive builder"));
     }
     if ($this->cacheFile === null) {
         $cacheFile = $this->generateCacheFile($environment);
         if (file_exists($cacheFile)) {
             unlink($cacheFile);
         }
     } else {
         $cacheFile = $this->cacheFile;
     }
     $errorMessage = null;
     try {
         $this->tar = new \PharData($cacheFile, null, null, static::PHAR_FORMAT);
         $this->compressionEntryPoint();
     } catch (\BadMethodCallException $e) {
         /**
          * This should not happen
          */
         $errorMessage = "You have badly called the method setEnvironment twice for %file";
     } catch (\UnexpectedValueException $e) {
         $errorMessage = "The file %file is corrupted";
     }
     if ($errorMessage !== null) {
         throw new TarArchiveException($this->translator->trans($errorMessage, ["%file" => $cacheFile]));
     }
     $this->cacheFile = $cacheFile;
     $this->environment = $environment;
     return $this;
 }
Пример #11
0
 protected function checkInterface()
 {
     /* Must implement either :
      *  - PropelSearchLoopInterface
      *  - ArraySearchLoopInterface
      */
     $searchInterface = false;
     if ($this instanceof PropelSearchLoopInterface) {
         if (true === $searchInterface) {
             throw new LoopException($this->translator->trans('Loop cannot implements multiple Search Interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`'), LoopException::MULTIPLE_SEARCH_INTERFACE);
         }
         $searchInterface = true;
     }
     if ($this instanceof ArraySearchLoopInterface) {
         if (true === $searchInterface) {
             throw new LoopException($this->translator->trans('Loop cannot implements multiple Search Interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`'), LoopException::MULTIPLE_SEARCH_INTERFACE);
         }
         $searchInterface = true;
     }
     if (false === $searchInterface) {
         throw new LoopException($this->translator->trans('Loop must implements one of the following interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`'), LoopException::SEARCH_INTERFACE_NOT_FOUND);
     }
     /* Only PropelSearch allows timestamp and version */
     if (!$this instanceof PropelSearchLoopInterface) {
         if (true === $this->timestampable) {
             throw new LoopException($this->translator->trans("Loop must implements 'PropelSearchLoopInterface' to be timestampable"), LoopException::NOT_TIMESTAMPED);
         }
         if (true === $this->versionable) {
             throw new LoopException($this->translator->trans("Loop must implements 'PropelSearchLoopInterface' to be versionable"), LoopException::NOT_VERSIONED);
         }
     }
 }
Пример #12
0
 /**
  *
  * Injects an associative array containing information for loop execution
  *
  * key is loop name
  * value is the class implementing/extending base loop classes
  *
  * ex :
  *
  * $loop = array(
  *  "product" => "Thelia\Loop\Product",
  *  "category" => "Thelia\Loop\Category",
  *  "myLoop" => "My\Own\Loop"
  * );
  *
  * @param  array                     $loopDefinition
  * @throws \InvalidArgumentException if loop name already exists
  */
 public function setLoopList(array $loopDefinition)
 {
     foreach ($loopDefinition as $name => $className) {
         if (array_key_exists($name, $this->loopDefinition)) {
             throw new \InvalidArgumentException($this->translator->trans("The loop name '%name' is already defined in %className class", ['%name' => $name, '%className' => $className]));
         }
         $this->loopDefinition[$name] = $className;
     }
 }
 /**
  * Parse one customergroupacl
  *
  * @param SimpleXMLElement $customerGroupAcl A customergroupacl
  * @param CustomerGroup $customerGroupModel CustomerGroup propel object for who the access have to be created
  *
  * @throws \Exception When an error is detected on xml file (customer group or acl don't exist)
  */
 protected function parseCustomerGroupAcl(SimpleXMLElement $customerGroupAcl, CustomerGroup $customerGroupModel)
 {
     $acl = AclQuery::create()->findOneByCode($customerGroupAcl->getAttributeAsPhp('aclcode'));
     if (null === $customerGroupModel) {
         throw new \Exception($this->translator->trans("Error in %a file the customer group '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupModel->getCode()], CustomerGroupAcl::DOMAIN_MESSAGE));
     }
     if (null === $acl) {
         throw new \Exception($this->translator->trans("Error in %a file the acl '%s' doesn't exist", ['%a' => $this->xmlFilePath, '%s' => $customerGroupAcl->getAttributeAsPhp('aclcode')], CustomerGroupAcl::DOMAIN_MESSAGE));
     }
     $this->parseAccesses($customerGroupAcl->children(), $acl, $customerGroupModel);
 }
Пример #14
0
 /**
  * Check if a hook has returned results. The hook should have been executed before, or an
  * InvalidArgumentException is thrown
  *
  * @param array $params
  *
  * @return boolean                   true if the hook is empty
  * @throws \InvalidArgumentException
  */
 protected function checkEmptyHook($params)
 {
     $hookName = $this->getParam($params, 'rel');
     if (null == $hookName) {
         throw new \InvalidArgumentException($this->translator->trans("Missing 'rel' parameter in ifhook/elsehook arguments"));
     }
     if (!isset($this->hookResults[$hookName])) {
         throw new \InvalidArgumentException($this->translator->trans("Related hook name '%name' is not defined.", ['%name' => $hookName]));
     }
     return is_string($this->hookResults[$hookName]) && '' === $this->hookResults[$hookName] || !is_string($this->hookResults[$hookName]) && $this->hookResults[$hookName]->isEmpty();
 }
Пример #15
0
 /**
  * @param  int                   $index
  * @return array|bool
  * @throws \OutOfBoundsException
  */
 public function getRow($index = 0, $reverseAliases = false)
 {
     if (empty($this->data)) {
         return false;
     } elseif (!isset($this->data[$index])) {
         throw new \OutOfBoundsException($this->translator->trans("Bad index value %idx", ["%idx" => $index]));
     }
     $row = $this->data[$index];
     if ($reverseAliases === true) {
         $row = $this->reverseAliases($row, $this->aliases);
     }
     return $row;
 }
Пример #16
0
 /**
  * Smarty function that replace the classic `intl` function.
  *
  * The attributes of the function are:
  * - `l`: the key
  * - `locale`: the locale. eg.: fr_FR
  * - `in_string`: set to 1 not add simple quote around the string. (default = 0)
  * - `use_default`: set to 1 to use the `l` string as a fallback. (default = 0)
  *
  * @param $params
  * @param $smarty
  * @return string
  */
 public function translate($params, $smarty)
 {
     $translation = '';
     if (empty($params["l"])) {
         throw new RuntimeException('Translation Error. Key is empty.');
     } elseif (empty($params["locale"])) {
         throw new RuntimeException('Translation Error. Locale is empty.');
     } else {
         $inString = 0 !== intval($params["in_string"]);
         $useDefault = 0 !== intval($params["use_default"]);
         $translation = $this->translator->trans($params["l"], [], 'install', $params["locale"], $useDefault);
         if (empty($translation)) {
             $translation = $inString ? '' : "NULL";
         } else {
             $translation = $this->con->quote($translation);
             // remove quote
             if ($inString) {
                 $translation = substr($translation, 1, -1);
             }
         }
     }
     return $translation;
 }
Пример #17
0
 public function throwFileNotFound($file)
 {
     throw new FileNotFoundException($this->translator->trans("The file %file is missing or is not readable", ["%file" => $file]));
 }
Пример #18
0
 public function checkLanguage($value, ExecutionContextInterface $context)
 {
     if (null === LangQuery::create()->findPk($value)) {
         $context->addViolation($this->translator->trans("The language \"%id\" doesn't exist", ["%id" => $value]));
     }
 }