Esempio n. 1
0
 /**
  * Returns all placeholders.
  * @param string|array|null $parent $root or $parent.
  * @param int $sanitize
  * @param array $only
  * @param array $exclude
  * @return array
  * @throws TemplateException
  */
 public function getAllPlaceholders($parent = null, $sanitize = null, array $only = [], array $exclude = [])
 {
     if (isset($parent)) {
         list(, , $template) = $this->getParentPlaceholder($parent);
     }
     if (!isset($template)) {
         $template = $this;
     }
     if ($template === false) {
         if ($this->throwException) {
             if (is_array($parent)) {
                 $parent = implode('.', $parent);
             }
             throw new TemplateException("Unknown scope: {$parent}");
         }
         return [];
     }
     return $this->sanitize(ArrayHelper::only($template->placeholders, $only, $exclude), $sanitize);
 }
Esempio n. 2
0
 protected static function getHash($token)
 {
     if (is_array($token)) {
         $token = ArrayHelper::only($token, [], static::$exclude);
         $token = serialize($token);
     }
     return crc32($token);
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function getAll(array $only = [], array $exclude = [], Sanitize $sanitize = null)
 {
     if (empty($_COOKIE)) {
         return [];
     }
     static::$data = Serialize::unserializeRecursive($_COOKIE);
     static::$data = $this->sanitize(static::$data, $sanitize);
     return static::$data = ArrayHelper::only(static::$data, $only, $exclude);
 }
Esempio n. 4
0
 /**
  * Returns all i18n-records by locale.
  *
  * @param array $only
  * @param array $exclude
  * @return array
  */
 public function getAll(array $only = [], array $exclude = [])
 {
     if (!isset(static::$data[$this->locale])) {
         return [];
     }
     return ArrayHelper::only(static::$data[$this->locale], $only, $exclude);
 }
Esempio n. 5
0
File: User.php Progetto: romeoz/rock
 /**
  * @inheritdoc
  */
 public function getAll(array $only = [], array $exclude = [])
 {
     if (!$this->getIsActive()) {
         return null;
     }
     return ArrayHelper::only($this->storage->get($this->container), $only, $exclude);
 }
Esempio n. 6
0
File: RBAC.php Progetto: romeoz/rock
 /**
  * @inheritdoc
  */
 public function getAll(array $only = [], array $exclude = [])
 {
     return ArrayHelper::only(static::$items, $only, $exclude);
 }
Esempio n. 7
0
 /**
  * @inheritdoc
  */
 public function getAll(array $only = [], array $exclude = [])
 {
     return ArrayHelper::only($_SESSION, $only, $exclude);
 }
Esempio n. 8
0
 protected function isREST($url, $controller, $filters)
 {
     $handlers = ArrayHelper::only($this->RESTHandlers, Helper::getValue($filters['only'], []), Helper::getValue($filters['exclude'], []));
     foreach ($handlers as $value) {
         if (!isset($value[3])) {
             $value[3] = null;
         }
         list($verbs, $pattern, $handler, $_filters) = $value;
         $filters = !empty($filters['filters']) ? $filters['filters'] : $_filters;
         if (StringHelper::isRegexp($pattern)) {
             $url = preg_quote($url, '/');
             $pattern = "~{$pattern}";
         }
         $pattern = str_replace('{url}', $url, $pattern);
         $this->params['controller'] = $controller;
         if ($this->isRoute($verbs, $pattern, $handler, $filters)) {
             $this->errors = 0;
             return true;
         } else {
             $this->errors |= $this->errors;
         }
     }
     return false;
 }
Esempio n. 9
0
 protected function errorsToPlaceholders(Model $model)
 {
     $errors = ArrayHelper::only($model->getErrors(), [], $model->safeAttributes());
     $this->template->addMultiPlaceholders($errors);
 }
Esempio n. 10
0
 protected function normalizeRules(array &$result = [], array &$aliases = [], array $rules, array $params = [], array $group = [])
 {
     foreach ($rules as $alias => $rule) {
         if ($rule[0] === self::REST) {
             $this->normalizeRules($result, $aliases, ArrayHelper::only($this->RESTHandlers, Helper::getValue($rule['only'], []), Helper::getValue($rule['exclude'], [])), ['prefix' => $alias, 'replace' => $rule[1], 'controller' => $rule[2], 'filters' => isset($rule['filters']) ? $rule['filters'] : null], $group);
             continue;
         }
         list(, $pattern) = $rule;
         if (is_string($alias)) {
             if (isset($params['replace'])) {
                 if (isset($params['prefix']) && !is_string($params['prefix'])) {
                     $params['prefix'] = $params['replace'];
                 }
                 $alias = "{$params['prefix']}.{$alias}";
             }
             if (isset($group['as'])) {
                 $alias = "{$group['as']}.{$alias}";
             }
         }
         $result[$alias] = $rule;
         if (isset($params['controller'])) {
             $result[$alias]['params']['controller'] = $params['controller'];
         }
         if (isset($params['filters']) && !isset($result[$alias][3])) {
             $result[$alias]['filters'] = $params['filters'];
         }
         if (!is_array($pattern)) {
             $value = $pattern;
             $pattern = [];
             $pattern[self::FILTER_PATH] = $value;
         }
         if (isset($pattern[self::FILTER_PATH])) {
             if (isset($params['replace'])) {
                 $pattern[self::FILTER_PATH] = is_array($params['replace']) ? strtr($pattern[self::FILTER_PATH], $params['replace']) : str_replace('{url}', $params['replace'], $pattern[self::FILTER_PATH]);
             }
             if (isset($group[self::FILTER_PATH])) {
                 $pattern[self::FILTER_PATH] = rtrim($group[self::FILTER_PATH], '/') . '/' . ltrim($pattern[self::FILTER_PATH], '/');
             }
         }
         foreach ($pattern as $key => &$data) {
             if (is_array($data)) {
                 foreach ($data as $k => $value) {
                     if (is_string($value)) {
                         $data[$k] = $this->parse($value, '.+');
                     }
                 }
                 continue;
             }
             $data = $key != self::FILTER_PATH ? $this->parse($data, '.+') : $this->parse($data);
         }
         $result[$alias][1] = $pattern;
         if (is_string($alias)) {
             $build = $this->buildAlias($pattern, $params, $group);
             $placeholders = ['self_path' => $this->request->getUrlWithoutArgs(), 'self_scheme' => $this->request->getScheme()];
             foreach ($this->request->rawGet() ?: [] as $name => $placeholder) {
                 $placeholders["self_query_{$name}"] = $placeholder;
             }
             Alias::setAlias(str_replace('/', '.', $alias), StringHelper::replace($build, $placeholders, false), false);
             $aliases[$alias] = $build;
         }
     }
 }
Esempio n. 11
0
 /**
  * @inheritdoc
  */
 public function getAll(array $only = [], array $exclude = [])
 {
     return ArrayHelper::only($this->_headers, $only, $exclude);
 }
Esempio n. 12
0
 /**
  * Returns all configs.
  *
  * @param bool $alias by alias
  * @param array $only list of items whose value needs to be returned.
  * @param array $exclude list of items whose value should NOT be returned.
  * @return array the array representation of the collection.
  */
 public static function getAll(array $only = [], array $exclude = [], $alias = false)
 {
     return $alias === true ? ArrayHelper::only(static::$classAliases, $only, $exclude) : ArrayHelper::only(static::$classNames, $only, $exclude);
 }