Пример #1
0
 /**
  * Init hashmap for a clean
  * html render
  */
 private function initHashmap()
 {
     // Calculate hashmaps (if they weren't just calculated)
     if (false == ArrayHelper::isAssociative(self::$md5VarHashmap)) {
         for ($i = 0; $i < count(self::$md5VarHashmap); $i++) {
             self::$md5VarHashmap[self::$md5VarHashmap[$i]] = md5(self::$md5VarHashmap[$i]);
             unset(self::$md5VarHashmap[$i]);
         }
     }
 }
Пример #2
0
 /**
  * @param string $url
  * @param array $arguments
  */
 public static function parseRouteUrl($url, $arguments = array())
 {
     preg_match_all(Route::VAR_MASK, $url, $matches);
     if (ArrayHelper::isAssociative($arguments)) {
         for ($i = 0, $len = count($matches[1]); $i < $len; $i++) {
             if (array_key_exists($matches[1][$i], $arguments)) {
                 $url = preg_replace('/' . $matches[0][$i] . '/', $arguments[$matches[1][$i]], $url);
             }
         }
     } else {
         for ($i = 0, $len = count($matches[1]); $i < $len; $i++) {
             if (array_key_exists($i, $arguments)) {
                 $url = preg_replace('/' . $matches[0][$i] . '/', $arguments[$i], $url);
             }
         }
     }
     return $url;
 }
Пример #3
0
 /**
  * Returns the default destination for
  * a method (e.g. view:index)
  *
  * @param  string $method
  * @return string
  */
 public function getDefaultDestination($method)
 {
     $urlLayout = explode('/', $this->getUrlLayout());
     $urlLayout = ArrayHelper::clean($urlLayout);
     $defaultMethod = 'index';
     for ($i = 0; $i < count($urlLayout); $i++) {
         if (true == preg_match('/' . $method . ':/', $urlLayout[$i])) {
             $exploded = explode(':', $urlLayout[$i]);
             $defaultMethod = end($exploded);
         }
     }
     return $defaultMethod;
 }
Пример #4
0
 /**
  * @return array
  */
 public function getParts()
 {
     return ArrayHelper::clean(explode("/", $this->fullFrom));
 }
Пример #5
0
 /**
  * Gets elements by path
  * sequence (in all xml files)
  *
  * @param  string $path
  * @return array
  */
 public function getElementsByPath($path)
 {
     $elements = array();
     foreach ($this->xmls as $xml) {
         $result = $xml->getElementsByPath($path);
         if (false != $result) {
             $elements[] = $result;
         }
     }
     return ArrayHelper::flatten($elements);
 }
Пример #6
0
 /**
  * Gets the variable from the match
  * of the pattern and the string
  *
  * @param  string $str
  * @param  integer $index
  * @return string|array
  */
 private static function getStringArguments($str, $index)
 {
     preg_match(self::SHORTCUT_IDENTIFIER_PATTERN, $str, $matches);
     $value = '';
     $index += 1;
     // Increase to avoid selecting the full $str
     if (array_key_exists($index, $matches)) {
         $value = trim($matches[$index]);
     }
     /**
      * Check if the value
      * is an array or not
      */
     if (preg_match(self::SHORTUCT_ARRAY_SYNTAX, $value)) {
         /**
          * Get the values of the array
          * sperated from the string
          */
         $arrayValues = ArrayHelper::trimExplode(',', $value);
         /**
          * Build associative array
          * from the given values
          */
         $value = array();
         foreach ($arrayValues as $val) {
             $expVal = ArrayHelper::trimExplode(':', $val);
             $value[$expVal[0]] = $expVal[1];
         }
     }
     return $value;
 }
Пример #7
0
 /**
  * Gets all element by a
  * path sequence. It creates
  * the list only for the last path
  * segment
  *
  * @param  string  $path
  * @param  boolean $collect
  * @return \Fewlines\Core\Xml\Tree\Element|boolean|array
  */
 public function getElementsByPath($path, $collect = true)
 {
     $parts = explode("/", $path);
     $parts = ArrayHelper::clean($parts);
     $rootName = $parts[0];
     $treeElement = $this->getTreeElement();
     if ($treeElement->getName() != $rootName || (!$this->isValid() || !$this->tree->hasRoot())) {
         return false;
     }
     $result = $treeElement;
     $resultList = array();
     for ($i = 1, $partsLen = count($parts); $i < $partsLen; $i++) {
         if (true == $collect && $i == $partsLen - 1) {
             $resultList = $result->getChildrenByName($parts[$i]);
         }
         if ($result) {
             $result = $result->getChildByName($parts[$i]);
         }
     }
     if (true == $collect) {
         if (false == empty($resultList)) {
             return $resultList;
         } else {
             if (false == empty($result)) {
                 return array($result);
             } else {
                 return array();
             }
         }
     }
     return $result;
 }
Пример #8
0
 /**
  * @param {array} $values
  * @return self
  */
 public function assignMultiple($values)
 {
     if (ArrayHelper::isAssociative($values)) {
         foreach ($values as $name => $content) {
             $this->assign($name, $content);
         }
     } else {
         throw new View\Exception\MultipleValuesNotAssociativeException('The array given is not associative. You need to pass a
             name for each variable content you want to assign to the
             view');
     }
     return $this;
 }
Пример #9
0
 /**
  * Get a translation from a file by a path
  *
  * @param  string|arary $path
  * @return string
  */
 public static function get($path)
 {
     $project = ProjectManager::getActiveProject();
     $project = $project ? $project : ProjectManager::getDefaultProject();
     $pathParts = ArrayHelper::clean(explode(self::SUBPATH_SEPERATOR, $path));
     $localeDir = PathHelper::createPath(array($project->getTranslationPath(), Locale::getKey()));
     $entryPoint = '';
     $entryPointIndex = 0;
     // Check if path is empty
     if (empty($pathParts)) {
         return '';
     }
     // Get entry point file
     for ($i = 0, $len = count($pathParts); $i < $len; $i++) {
         $isFile = false;
         $localeDir = PathHelper::getRealPath($localeDir);
         for ($x = 0, $lenX = count(self::$translationTypes); $x < $lenX; $x++) {
             $fileExt = self::$translationTypes[$x];
             $pathPart = $pathParts[$i];
             $isFile = is_file($localeDir . $pathPart . '.' . $fileExt);
             // Escape loop if file was found
             if (true == $isFile) {
                 break;
             }
         }
         // Attach current "dir" to the localdir (next level)
         $localeDir .= $pathPart;
         // Excape loop if entry point was found
         if (true == $isFile) {
             $entryPointIndex = $i;
             $entryPoint = $localeDir . '.' . $fileExt;
             break;
         }
     }
     /**
      * If there is no entry point take
      * all supported translation files
      * from the given directory
      */
     if (empty($entryPoint) && is_dir($localeDir)) {
         $files = DirHelper::scanDir($localeDir);
         $names = array();
         foreach ($files as $file) {
             $extension = pathinfo($file['path'], PATHINFO_EXTENSION);
             $filename = pathinfo($file['path'], PATHINFO_FILENAME);
             if (array_search($extension, self::$translationTypes) !== false) {
                 $names[] = $filename;
             }
         }
         return $names;
     }
     // if (true == empty($entryPoint)) {
     //     throw new Translator\Exception\EntryPointNotFoundException("No entry point (file) found for: " . (string) $path);
     // }
     $pathParts = array_slice($pathParts, $entryPointIndex + 1);
     $pathParts = ArrayHelper::clean($pathParts);
     // The default translation value
     $value = $path;
     /**
      * Operate with the key functions for different file types.
      * At this point we are handling valid values
      */
     switch ($fileExt) {
         case self::$translationTypes[0]:
             $value = self::getValueByKeyPHP($entryPoint, $pathParts);
             break;
         case self::$translationTypes[1]:
             $value = self::getValueByKeyCSV($entryPoint, $pathParts);
             break;
     }
     /**
      * If the value is a array and empty it doesn't
      * need to be returned. Return a empty string
      * instead
      */
     if (empty($value)) {
         return '';
     } else {
         return $value;
     }
 }
Пример #10
0
 /**
  * Gets a list of all elements with this name.
  * Recursive strategy enabled by default.
  * It also collects all results if the
  * parameter is set to true (Without reference
  * variables)
  *
  * @param  string  $name
  * @param  boolean $recursive
  * @param  boolean $collect
  * @return Element|boolean|array
  */
 public function getChildrenByName($name, $collect = true, $recursive = true)
 {
     $children = array();
     for ($i = 0; $i < count($this->children); $i++) {
         $child = $this->children[$i];
         if ($child->getName() == $name) {
             if (!$collect) {
                 return $child;
             } else {
                 $children[] = $child;
             }
         }
         if ($child->countChildren() > 0 && $recursive) {
             if (!$collect) {
                 $depthChild = $child->getChildByName($name, $recursive);
                 if ($depthChild) {
                     return $depthChild;
                 }
             } else {
                 $depthChilds = $child->getChildrenByName($name, $collect, $recursive);
                 if ($depthChilds) {
                     $children[] = $depthChilds;
                 }
             }
         }
     }
     if (true == $collect) {
         return ArrayHelper::flatten($children);
     }
     return false;
 }