Example #1
0
 public static function isIndexExists($array, $key, $message = null)
 {
     Assert::isArray($array);
     if (!array_key_exists($key, $array)) {
         throw new WrongArgumentException($message . ', ' . self::dumpArgument($key));
     }
 }
 /**
  * @return PrimitiveMultiList
  **/
 public function setDefault($default)
 {
     Assert::isArray($default);
     foreach ($default as $index) {
         Assert::isTrue(array_key_exists($index, $this->list));
     }
     return parent::setDefault($default);
 }
 /**
  * @return PrimitiveRegistryList
  **/
 public function setValue($value)
 {
     if ($value) {
         Assert::isArray($value);
         Assert::isInstance(current($value), Registry::class);
     }
     $this->value = $value;
     return $this;
 }
Example #4
0
 protected function cacheListByQuery(SelectQuery $query, $array)
 {
     if ($array !== Cache::NOT_FOUND) {
         Assert::isArray($array);
         Assert::isTrue(current($array) instanceof Identifiable);
     }
     Cache::me()->mark($this->className)->add($this->makeQueryKey($query, self::SUFFIX_LIST), $array, Cache::EXPIRES_FOREVER);
     return $array;
 }
Example #5
0
 public function __construct($field, $words, $logic)
 {
     if (is_string($field)) {
         $field = new DBField($field);
     }
     Assert::isArray($words);
     $this->field = $field;
     $this->words = $words;
     $this->logic = $logic;
 }
Example #6
0
 protected function cacheListByQuery(SelectQuery $query, $array, $expires = Cache::EXPIRES_FOREVER)
 {
     if ($array !== Cache::NOT_FOUND) {
         Assert::isArray($array);
         Assert::isTrue(current($array) instanceof Identifiable);
     }
     $key = $this->makeQueryKey($query, self::SUFFIX_LIST);
     Cache::me()->mark($this->className)->set($key, ['tags' => $this->getTagsForQuery($query), 'data' => $array], $expires);
     //			SemaphorePool::me()->free(self::LOCK_PREFIX.$key);
     return $array;
 }
Example #7
0
 protected function cacheListByQuery(SelectQuery $query, $array)
 {
     if ($array !== Cache::NOT_FOUND) {
         Assert::isArray($array);
         Assert::isTrue(current($array) instanceof Identifiable);
     }
     $cache = Cache::me();
     $key = $this->makeQueryKey($query, self::SUFFIX_LIST);
     if ($this->handler->touch($this->keyToInt($key))) {
         $cache->mark($this->className)->add($key, $array, Cache::EXPIRES_FOREVER);
     }
     return $array;
 }
Example #8
0
 /**
  * @deprecated to support old convert method in CurlHttpClient
  *
  * @param array $array
  *
  * @return string
  */
 public static function toStringOneDeepLvl($array)
 {
     Assert::isArray($array);
     $result = [];
     foreach ($array as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $valueKey => $simpleValue) {
                 $result[] = $key . '[' . $valueKey . ']=' . urlencode($simpleValue);
             }
         } else {
             $result[] = $key . '=' . urlencode($value);
         }
     }
     return implode('&', $result);
 }
 public function importValue($value)
 {
     if ($value !== null) {
         Assert::isArray($value);
     } else {
         return null;
     }
     $result = true;
     $resultValue = [];
     foreach ($value as $id => $form) {
         Assert::isInstance($form, Form::class);
         $resultValue[$id] = $form;
         if ($form->getErrors()) {
             $result = false;
         }
     }
     $this->value = $resultValue;
     return $result;
 }
Example #10
0
 /**
  * @param array $scope
  * from http request
  * looks like foo[1]=42&bar[1]=test&foo[2]=44&bar[2]=anothertest
  */
 public function import(array $scope)
 {
     $this->imported = true;
     foreach ($scope as $name => $paramList) {
         /**
          * @var array $paramList
          * looks like array(1 => 42, 2 => 44)
          */
         Assert::isArray($paramList);
         foreach ($paramList as $key => $value) {
             if (!isset($this->formList[$key])) {
                 $this->formList[$key] = clone $this->sampleForm;
             }
             $this->formList[$key]->importMore([$name => $value]);
         }
     }
     reset($this->formList);
     return $this;
 }
Example #11
0
 protected function cacheListByQuery(SelectQuery $query, $array)
 {
     if ($array !== Cache::NOT_FOUND) {
         Assert::isArray($array);
         Assert::isTrue(current($array) instanceof Identifiable);
     }
     $cache = Cache::me();
     $listKey = $this->makeQueryKey($query, self::SUFFIX_LIST);
     $semKey = $this->keyToInt($this->indexKey);
     $pool = SemaphorePool::me();
     if ($pool->get($semKey)) {
         $this->syncMap($listKey);
         $cache->mark($this->className)->add($listKey, $array, Cache::EXPIRES_FOREVER);
         if ($array !== Cache::NOT_FOUND) {
             foreach ($array as $object) {
                 $this->cacheById($object);
             }
         }
         $pool->free($semKey);
     }
     return $array;
 }
Example #12
0
 private static function prepareFullText($words, $logic)
 {
     Assert::isArray($words);
     $retval = self::quoteValue(implode(' ', $words));
     if (self::IN_BOOLEAN_MODE === $logic) {
         return addcslashes($retval, '+-<>()~*"') . ' ' . 'IN BOOLEAN MODE';
     } else {
         return $retval;
     }
 }
Example #13
0
 public function __construct(EntityProto $proto, &$object)
 {
     Assert::isArray($object);
     return parent::__construct($proto, $object);
 }
Example #14
0
 public function makeList($objectsList, $recursive = true)
 {
     if ($objectsList === null) {
         return null;
     }
     Assert::isArray($objectsList);
     $result = [];
     foreach ($objectsList as $id => $object) {
         $result[$id] = $this->makeListItemBuilder($object)->make($object, $recursive);
     }
     return $result;
 }
Example #15
0
 /**
  * @deprecated by array_combine($array, $array)
  **/
 public static function getMirrorValues($array)
 {
     Assert::isArray($array);
     $result = [];
     foreach ($array as $value) {
         Assert::isTrue(is_integer($value) || is_string($value), 'only integer or string values accepted');
         $result[$value] = $value;
     }
     return $result;
 }
Example #16
0
 /**
  * @return CurlHttpClient
  **/
 public function addRequest(HttpRequest $request, $options = [])
 {
     Assert::isArray($options);
     $key = $this->getRequestKey($request);
     if (isset($this->multiRequests[$key])) {
         throw new WrongArgumentException('There is allready such alias');
     }
     $this->multiRequests[$key] = $request;
     foreach ($options as $k => $val) {
         $this->multiThreadOptions[$key][$k] = $val;
     }
     return $this;
 }
Example #17
0
 public function cleanHref($scope, $absolute = null)
 {
     Assert::isArray($scope);
     $path = $this->navigationSchema ? $this->navigationSchema->extractPath($scope) : null;
     return $this->href($path . '?' . $this->buildQuery($scope), $absolute);
 }
Example #18
0
 /**
  * @return ContentTypeHeader
  **/
 public function setParametersList($parameters)
 {
     Assert::isArray($parameters);
     $this->parameters = $parameters;
     return $this;
 }
Example #19
0
 /**
  * @throws WrongArgumentException
  * @return PrimitiveFile
  **/
 public function setAllowedMimeTypes($mimes)
 {
     Assert::isArray($mimes);
     $this->allowedMimeTypes = $mimes;
     return $this;
 }
 /**
  * Adds values from associative array.
  * @return InsertOrUpdateQuery
  **/
 public function arraySet($fields)
 {
     Assert::isArray($fields);
     $this->fields = array_merge($this->fields, $fields);
     return $this;
 }
Example #21
0
 /**
  * @throws WrongArgumentException
  * @return UnifiedContainer
  **/
 public function save()
 {
     Assert::isArray($this->list, "that's not an array :-/");
     if (!$this->fetched) {
         throw new WrongStateException('do not want to save non-fetched collection');
     }
     $list = $this->list;
     $clones = $this->clones;
     $ids = $insert = $delete = $update = [];
     if ($this->lazy) {
         foreach ($list as $id) {
             if (!isset($clones[$id])) {
                 $insert[] = $ids[$id] = $id;
             } else {
                 $ids[$id] = $id;
             }
         }
         foreach ($clones as $id) {
             if (!isset($ids[$id])) {
                 $delete[] = $id;
             }
         }
     } else {
         foreach ($list as $object) {
             $id = $object->getId();
             if (null === $id) {
                 $insert[] = $object;
             } elseif (isset($clones[$id]) && $this->comparator->compare($object, $clones[$id]) != 0) {
                 $update[] = $object;
             } elseif (!isset($clones[$id])) {
                 $insert[] = $object;
             }
             if (null !== $id) {
                 $ids[$id] = $object;
             }
         }
         foreach ($clones as $id => $object) {
             if (!isset($ids[$id])) {
                 $delete[] = $object;
             }
         }
     }
     InnerTransactionWrapper::create()->setDao($this->getDao())->setFunction([$this->worker, 'sync'])->run($insert, $update, $delete);
     $this->clones = [];
     $this->syncClones();
     $this->dao->uncacheLists();
     return $this;
 }
Example #22
0
 public static function arrayAssign($scope, $array)
 {
     Assert::isArray($array);
     foreach ($array as $var) {
         if (isset($scope[$var])) {
             $_SESSION[$var] = $scope[$var];
         }
     }
 }