当前位置: 首页>>代码示例>>PHP>>正文


PHP Validators::isList方法代码示例

本文整理汇总了PHP中Nette\Utils\Validators::isList方法的典型用法代码示例。如果您正苦于以下问题:PHP Validators::isList方法的具体用法?PHP Validators::isList怎么用?PHP Validators::isList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Utils\Validators的用法示例。


在下文中一共展示了Validators::isList方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validateDeeply

 /**
  * Recursively validate data using dot notation
  * @param  IField $field 
  * @param  array  $data 
  * @param  string $path
  * @return array
  */
 protected function validateDeeply(IField $field, $data, $path)
 {
     $errors = array();
     if (Validators::isList($data) && count($data)) {
         foreach ($data as $item) {
             $newErrors = $this->validateDeeply($field, $item, $path);
             $errors = array_merge($errors, $newErrors);
         }
     } else {
         $keys = explode(".", $path);
         $last = count($keys) - 1;
         foreach ($keys as $index => $key) {
             $isLast = $index == $last;
             $value = isset($data[$key]) ? $data[$key] : NULL;
             if (is_array($value)) {
                 $newPath = Strings::replace($path, "~^{$key}\\.~");
                 $newErrors = $this->validateDeeply($field, $value, $newPath);
                 $errors = array_merge($errors, $newErrors);
                 break;
                 // because recursion already handled this path validation
             } else {
                 if ($isLast || $value === NULL) {
                     $newErrors = $field->validate($value);
                     $errors = array_merge($errors, $newErrors);
                     break;
                 }
             }
         }
     }
     return $errors;
 }
开发者ID:lucien144,项目名称:Restful,代码行数:38,代码来源:ValidationScope.php

示例2: __construct

 /**
  * @param array|string $setCookies
  */
 public function __construct($setCookies = NULL)
 {
     if (Nette\Utils\Validators::isList($setCookies) || is_scalar($setCookies)) {
         $this->parse(is_array($setCookies) ? $setCookies : (array) $setCookies);
     } else {
         foreach ((array) $setCookies as $name => $value) {
             $this->{$name} = $value;
         }
     }
 }
开发者ID:noikiy,项目名称:Curl,代码行数:13,代码来源:HttpCookies.php

示例3: setValue

 /**
  * Sets control's value.
  *
  * @param  array|Nette\Http\FileUpload
  * @return Nette\Http\FileUpload  provides a fluent interface
  */
 public function setValue($value)
 {
     if (is_array($value)) {
         if (Nette\Utils\Validators::isList($value)) {
             foreach ($value as $i => $file) {
                 $this->value[$i] = $file instanceof Http\FileUpload ? $file : new Http\FileUpload($file);
             }
         } else {
             $this->value = array(new Http\FileUpload($value));
         }
     } elseif ($value instanceof Http\FileUpload) {
         $this->value = array($value);
     } else {
         $this->value = new Http\FileUpload(NULL);
     }
     return $this;
 }
开发者ID:fvozar,项目名称:images,代码行数:23,代码来源:UploadControl.php

示例4: encode

 /**
  * Returns the NEON representation of a value.
  * @param  mixed
  * @param  int
  * @return string
  */
 public static function encode($var, $options = NULL)
 {
     if ($var instanceof \DateTime) {
         return $var->format('Y-m-d H:i:s O');
     } elseif ($var instanceof NeonEntity) {
         return self::encode($var->value) . '(' . substr(self::encode($var->attributes), 1, -1) . ')';
     }
     if (is_object($var)) {
         $obj = $var;
         $var = array();
         foreach ($obj as $k => $v) {
             $var[$k] = $v;
         }
     }
     if (is_array($var)) {
         $isList = Validators::isList($var);
         $s = '';
         if ($options & self::BLOCK) {
             if (count($var) === 0) {
                 return "[]";
             }
             foreach ($var as $k => $v) {
                 $v = self::encode($v, self::BLOCK);
                 $s .= ($isList ? '-' : self::encode($k) . ':') . (Strings::contains($v, "\n") ? "\n\t" . str_replace("\n", "\n\t", $v) : ' ' . $v) . "\n";
                 continue;
             }
             return $s;
         } else {
             foreach ($var as $k => $v) {
                 $s .= ($isList ? '' : self::encode($k) . ': ') . self::encode($v) . ', ';
             }
             return ($isList ? '[' : '{') . substr($s, 0, -2) . ($isList ? ']' : '}');
         }
     } elseif (is_string($var) && !is_numeric($var) && !preg_match('~[\\x00-\\x1F]|^\\d{4}|^(true|false|yes|no|on|off|null)$~i', $var) && preg_match('~^' . self::$patterns[4] . '$~', $var)) {
         return $var;
     } elseif (is_float($var)) {
         $var = var_export($var, TRUE);
         return Strings::contains($var, '.') ? $var : $var . '.0';
     } else {
         return json_encode($var);
     }
 }
开发者ID:exesek,项目名称:nette20login,代码行数:48,代码来源:Neon.php

示例5: formatStatement

 /**
  * Formats PHP code for class instantiating, function calling or property setting in PHP.
  * @return string
  * @internal
  */
 public function formatStatement(Statement $statement, $self = NULL)
 {
     $entity = $this->normalizeEntity($statement->entity);
     $arguments = $statement->arguments;
     if (is_string($entity) && Strings::contains($entity, '?')) {
         // PHP literal
         return $this->formatPhp($entity, $arguments, $self);
     } elseif ($service = $this->getServiceName($entity)) {
         // factory calling or service retrieving
         if ($this->definitions[$service]->shared) {
             if ($arguments) {
                 throw new ServiceCreationException("Unable to call service '{$entity}'.");
             }
             return $this->formatPhp('$this->getService(?)', array($service));
         }
         $params = array();
         foreach ($this->definitions[$service]->parameters as $k => $v) {
             $params[] = preg_replace('#\\w+$#', '\\$$0', is_int($k) ? $v : $k) . (is_int($k) ? '' : ' = ' . PhpHelpers::dump($v));
         }
         $rm = new Nette\Reflection\GlobalFunction(create_function(implode(', ', $params), ''));
         $arguments = Helpers::autowireArguments($rm, $arguments, $this);
         return $this->formatPhp('$this->?(?*)', array(Container::getMethodName($service, FALSE), $arguments), $self);
     } elseif ($entity === 'not') {
         // operator
         return $this->formatPhp('!?', array($arguments[0]));
     } elseif (is_string($entity)) {
         // class name
         if ($constructor = Nette\Reflection\ClassType::from($entity)->getConstructor()) {
             $this->addDependency($constructor->getFileName());
             $arguments = Helpers::autowireArguments($constructor, $arguments, $this);
         } elseif ($arguments) {
             throw new ServiceCreationException("Unable to pass arguments, class {$entity} has no constructor.");
         }
         return $this->formatPhp("new {$entity}" . ($arguments ? '(?*)' : ''), array($arguments), $self);
     } elseif (!Validators::isList($entity) || count($entity) !== 2) {
         throw new Nette\InvalidStateException("Expected class, method or property, " . PhpHelpers::dump($entity) . " given.");
     } elseif ($entity[0] === '') {
         // globalFunc
         return $this->formatPhp("{$entity['1']}(?*)", array($arguments), $self);
     } elseif (Strings::contains($entity[1], '$')) {
         // property setter
         Validators::assert($arguments, 'list:1', "setup arguments for '" . Nette\Callback::create($entity) . "'");
         if ($this->getServiceName($entity[0], $self)) {
             return $this->formatPhp('?->? = ?', array($entity[0], substr($entity[1], 1), $arguments[0]), $self);
         } else {
             return $this->formatPhp($entity[0] . '::$? = ?', array(substr($entity[1], 1), $arguments[0]), $self);
         }
     } elseif ($service = $this->getServiceName($entity[0], $self)) {
         // service method
         if ($this->definitions[$service]->class) {
             $arguments = $this->autowireArguments($this->definitions[$service]->class, $entity[1], $arguments);
         }
         return $this->formatPhp('?->?(?*)', array($entity[0], $entity[1], $arguments), $self);
     } else {
         // static method
         $arguments = $this->autowireArguments($entity[0], $entity[1], $arguments);
         return $this->formatPhp("{$entity['0']}::{$entity['1']}(?*)", array($arguments), $self);
     }
 }
开发者ID:BroukPytlik,项目名称:agility,代码行数:64,代码来源:ContainerBuilder.php

示例6: insert

 public function insert($data)
 {
     if ($data instanceof \Traversable && !$data instanceof Selection) {
         $data = iterator_to_array($data);
     }
     if (Nette\Utils\Validators::isList($data)) {
         foreach (array_keys($data) as $key) {
             $data[$key][$this->column] = $this->active;
         }
     } else {
         $data[$this->column] = $this->active;
     }
     return parent::insert($data);
 }
开发者ID:BroukPytlik,项目名称:agility,代码行数:14,代码来源:GroupedSelection.php

示例7: autowireArguments

 /**
  * Creates a list of arguments using autowiring.
  *
  * @return array
  */
 public function autowireArguments($class, $method, array $arguments)
 {
     $rc = Nette\Reflection\ClassType::from($class);
     if (!$rc->hasMethod($method)) {
         if (!Nette\Utils\Validators::isList($arguments)) {
             throw new ServiceCreationException("Unable to pass specified arguments to {$class}::{$method}().");
         }
         return $arguments;
     }
     $rm = $rc->getMethod($method);
     if ($rm->isAbstract() || !$rm->isPublic()) {
         throw new ServiceCreationException("{$rm} is not callable.");
     }
     $this->addDependency($rm->getFileName());
     return Helpers::autowireArguments($rm, $arguments, $this);
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:21,代码来源:ContainerBuilder.php

示例8: wherePrimary

 /**
  * Adds condition for primary key.
  * @param  mixed
  * @return self
  */
 public function wherePrimary($key)
 {
     if (is_array($this->primary) && Nette\Utils\Validators::isList($key)) {
         foreach ($this->primary as $i => $primary) {
             $this->where($primary, $key[$i]);
         }
     } elseif (is_array($key)) {
         // key contains column names
         $this->where($key);
     } else {
         $this->where($this->getPrimary(), $key);
     }
     return $this;
 }
开发者ID:genextwebs,项目名称:dropbox-sample,代码行数:19,代码来源:Selection.php

示例9: formatQuery

 /**
  * @param string $query
  * @param array $params
  * @param array $types
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Nette\Utils\RegexpException
  * @return string
  */
 public static function formatQuery($query, $params, array $types = [], AbstractPlatform $platform = NULL)
 {
     if (!$platform) {
         $platform = new Doctrine\DBAL\Platforms\MySqlPlatform();
     }
     if (!$types) {
         foreach ($params as $key => $param) {
             if (is_array($param)) {
                 $types[$key] = Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
             } else {
                 $types[$key] = 'string';
             }
         }
     }
     try {
         list($query, $params, $types) = \Doctrine\DBAL\SQLParserUtils::expandListParameters($query, $params, $types);
     } catch (Doctrine\DBAL\SQLParserUtilsException $e) {
     }
     $formattedParams = [];
     foreach ($params as $key => $param) {
         if (isset($types[$key])) {
             if (is_scalar($types[$key]) && array_key_exists($types[$key], Type::getTypesMap())) {
                 $types[$key] = Type::getType($types[$key]);
             }
             /** @var Type[] $types */
             if ($types[$key] instanceof Type) {
                 $param = $types[$key]->convertToDatabaseValue($param, $platform);
             }
         }
         $formattedParams[] = SimpleParameterFormatter::format($param);
     }
     $params = $formattedParams;
     if (Nette\Utils\Validators::isList($params)) {
         $parts = explode('?', $query);
         if (count($params) > $parts) {
             throw new Kdyby\Doctrine\InvalidStateException("Too mny parameters passed to query.");
         }
         return implode('', Kdyby\Doctrine\Helpers::zipper($parts, $params));
     }
     return Strings::replace($query, '~(\\:[a-z][a-z0-9]*|\\?[0-9]*)~i', function ($m) use(&$params) {
         if (substr($m[0], 0, 1) === '?') {
             if (strlen($m[0]) > 1) {
                 if (isset($params[$k = substr($m[0], 1)])) {
                     return $params[$k];
                 }
             } else {
                 return array_shift($params);
             }
         } else {
             if (isset($params[$k = substr($m[0], 1)])) {
                 return $params[$k];
             }
         }
         return $m[0];
     });
 }
开发者ID:LidskaSila,项目名称:Doctrine,代码行数:65,代码来源:Panel.php

示例10: validateAssetsBuildColList

 /**
  * Validate assets and build list of collection names.
  *
  * @param array $assets
  * @param NULL|string $parentName
  * @throws \Mike227\NAssetic\Exceptions\ConfigurationException
  */
 private function validateAssetsBuildColList(array $assets, $parentName = NULL)
 {
     // Validate assets
     foreach ($assets as $collectionName => $asset) {
         if (is_string($asset)) {
             // file definition
             return;
         }
         // Build list of collection names.
         // It is used to check if the collection exists (if is found reference to a collection).
         $collectionName = $parentName ? $parentName . '.' . $collectionName : $collectionName;
         $this->assetsNames[] = $collectionName;
         // [asset1, asset2, asset3] is equivalent to ['assets' => [asset1, asset2, asset3]]
         if (Validators::isList($asset)) {
             $asset = array('assets' => $asset);
         }
         Validators::assert($asset, 'array');
         foreach ($asset as $key => $value) {
             if (!in_array($key, $this->allowedKeysAssets)) {
                 throw new ConfigurationException("Key \"{$key}\" is not allowed in 'assets' configuration. Allowed keys are: " . implode(" ", $this->allowedKeysAssets));
             }
             if ($key === 'assets') {
                 Validators::assert($value, 'array');
                 $this->validateAssetsBuildColList($value, $collectionName);
             } else {
                 Validators::assert($key, 'string:1..');
             }
         }
     }
 }
开发者ID:mike227,项目名称:n-assetic,代码行数:37,代码来源:Extension.php

示例11: getRecursiveDiff

 /**
  * @param array $arr1
  * @param array $arr2
  * @return array
  */
 protected function getRecursiveDiff($arr1, $arr2)
 {
     $isList = Validators::isList($arr1);
     $arr2IsList = Validators::isList($arr2);
     foreach ($arr1 as $key => $item) {
         if (!is_array($arr1[$key])) {
             // if key is numeric, remove the same value
             if (is_numeric($key) && ($pos = array_search($arr1[$key], $arr2)) !== FALSE) {
                 unset($arr1[$key]);
             } else {
                 if (!$isList && isset($arr2[$key]) || $isList && $arr2IsList && array_search($item, $arr2) !== FALSE) {
                     unset($arr1[$key]);
                 }
             }
             //
         } elseif (isset($arr2[$key])) {
             $arr1[$key] = $item = $this->getRecursiveDiff($arr1[$key], $arr2[$key]);
             if (is_array($item) && count($item) === 0) {
                 unset($arr1[$key]);
             }
         }
     }
     if ($isList) {
         $arr1 = array_merge($arr1);
     }
     return $arr1;
 }
开发者ID:svobodni,项目名称:web,代码行数:32,代码来源:BaseInstaller.php

示例12: formatStatement

 function formatStatement(Statement $statement, $self = NULL)
 {
     $arguments = (array) $statement->arguments;
     if ($statement->entity instanceof PhpLiteral) {
         return $this->formatPhp('call_user_func_array(?, ?)', array($statement->entity, $arguments));
     }
     $entity = explode('::', $statement->entity);
     if (strpos($statement->entity, '::') === FALSE && ($service = $this->getServiceName($statement->entity))) {
         if ($this->definitions[$service]->shared) {
             throw new ServiceCreationException("Unable to call service '{$statement->entity}'.");
         }
         $params = array();
         foreach ($this->definitions[$service]->parameters as $k => $v) {
             $params[] = preg_replace('#\\w+$#', '\\$$0', is_int($k) ? $v : $k) . (is_int($k) ? '' : ' = ' . PhpHelpers::dump($v));
         }
         $rm = new \ReflectionFunction(create_function(implode(', ', $params), ''));
         $arguments = Helpers::autowireArguments($rm, $arguments, $this);
         return $this->formatPhp('$this->?(?*)', array('create' . ucfirst($service), $arguments), $self);
     } elseif (strpos($statement->entity, '::') === FALSE) {
         if ($constructor = Nette\Reflection\ClassType::from($statement->entity)->getConstructor()) {
             $this->addDependency($constructor->getFileName());
             $arguments = Helpers::autowireArguments($constructor, $arguments, $this);
         } elseif ($arguments) {
             throw new ServiceCreationException("Unable to pass arguments, class {$statement->entity} has no constructor.");
         }
         return $this->formatPhp("new {$statement->entity}" . ($arguments ? '(?*)' : ''), array($arguments));
     } elseif (!Validators::isList($entity) || count($entity) !== 2) {
         throw new Nette\InvalidStateException("Expected class, method or property, {$statement->entity} given.");
     } elseif ($entity[0] === '') {
         return $this->formatPhp("{$entity['1']}(?*)", array($arguments), $self);
     } elseif (strpos($statement->entity, '$') !== FALSE) {
         if ($this->getServiceName($entity[0], $self)) {
             return $this->formatPhp('?->? = ?', array($entity[0], substr($entity[1], 1), reset($arguments)), $self);
         } else {
             return $this->formatPhp($entity[0] . '::$? = ?', array(substr($entity[1], 1), reset($arguments)), $self);
         }
     } elseif ($service = $this->getServiceName($entity[0], $self)) {
         if ($this->definitions[$service]->class) {
             $arguments = $this->autowireArguments($this->expand($this->definitions[$service]->class), $entity[1], $arguments);
         }
         return $this->formatPhp('?->?(?*)', array($entity[0], $entity[1], $arguments), $self);
     } else {
         $arguments = $this->autowireArguments($entity[0], $entity[1], $arguments);
         return $this->formatPhp("{$entity['0']}::{$entity['1']}(?*)", array($arguments), $self);
     }
 }
开发者ID:skapytek,项目名称:scripts,代码行数:46,代码来源:nette.min.php


注:本文中的Nette\Utils\Validators::isList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。