Esempio n. 1
0
 public function __construct($callable = NULL, $uri = NULL, $exceptions = [], $aliases = [])
 {
     \UArray::doConvertToArray($exceptions);
     \UArray::doConvertToArray($aliases);
     $this->callable = $callable;
     $this->uri = $uri;
     $this->exceptions = $exceptions;
     $this->aliases = $aliases;
 }
Esempio n. 2
0
 public function reload()
 {
     $map = json_decode($this->seed, TRUE);
     \UArray::doConvertToArray($map);
     $result = [];
     foreach ($map as $key => $item) {
         $validation = $this->formatItem($item, $key);
         if ($validation) {
             $result[$key] = $item;
         }
     }
     $this->map = $result;
 }
Esempio n. 3
0
 public function byData($data)
 {
     \UArray::doConvertToArray($data);
     $model = new $this();
     $model->id = $this->entity->extractId($data);
     foreach ($data as $name => $seed) {
         $attribute = $model->getAttribute($name);
         if (is_object($attribute)) {
             $attribute->setSeed($seed);
         } else {
             $model->set($name, $seed);
         }
     }
     $model->initialize();
     return $model;
 }
Esempio n. 4
0
 public function set($remoteModels)
 {
     $this->remoteModels = [];
     $this->changed = TRUE;
     \UArray::doConvertToArray($remoteModels);
     if ($this->uniqueRemote) {
         $remoteModels = array_slice($remoteModels, 0, 1);
     }
     foreach ($remoteModels as $model) {
         if (is_numeric($model)) {
             $model = $this->getRemoteModel()->entity->fetchById($model);
         } else {
             if (!\Staq\Util::isStack($model, $this->getRemoteClass())) {
                 $message = 'Input of type "' . $this->getRemoteClass() . '", but "' . gettype($model) . '" given.';
                 throw new \Stack\Exception\NotRightInput($message);
             }
         }
         if ($model && $model->exists()) {
             $this->remoteModels[] = $model;
         }
     }
     return $this;
 }
Esempio n. 5
0
 public function test_do_convert_to_array__object__exception()
 {
     $array = new \Exception();
     $array->entry = 'a string';
     \UArray::doConvertToArray($array);
     $this->assertEquals(array('entry' => 'a string'), $array);
 }
Esempio n. 6
0
 protected function findExtensionPath($namespace)
 {
     foreach ($this->namespaces as $baseNamespace => $basePathList) {
         if (\UString::isStartWith($namespace, $baseNamespace)) {
             \UArray::doConvertToArray($basePathList);
             foreach ($basePathList as $basePath) {
                 \UString::doEndWith($basePath, DIRECTORY_SEPARATOR);
                 \UString::doNotStartWith($namespace, $baseNamespace);
                 \UString::doNotStartWith($namespace, '\\');
                 $path = str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
                 $path = $basePath . $path;
                 if (is_dir($path)) {
                     return $path;
                 }
             }
         }
     }
 }
Esempio n. 7
0
 public static function substrAfterLast($haystack, $needles)
 {
     \UArray::doConvertToArray($needles);
     $result = $haystack;
     foreach ($needles as $needle) {
         if (!empty($needle) && \UString::has($haystack, $needle)) {
             $cut = substr($haystack, strrpos($haystack, $needle) + strlen($needle));
             if (strlen($cut) < strlen($result)) {
                 $result = $cut;
             }
         }
     }
     return $result;
 }
Esempio n. 8
0
 protected function removingValues(&$values, &$key)
 {
     $reference_key = preg_replace('/\\s*-\\s*$/', '', $key);
     $reference =& $values[$reference_key];
     $remove = $values[$key];
     unset($values[$key]);
     \UArray::doConvertToArray($reference);
     \UArray::doRemoveValue($reference, $remove);
     $key = $reference_key;
 }
Esempio n. 9
0
 public static function removeValue($array, $values)
 {
     \UArray::doConvertToArray($values);
     $indexes = array();
     foreach ($values as $value) {
         $indexes = array_merge($indexes, array_keys($array, $value));
     }
     return \UArray::removeIndex($array, $indexes);
 }
Esempio n. 10
0
 public function __construct($array, $options = array())
 {
     parent::__construct($array);
     \UArray::doConvertToArray($options);
     call_user_func_array(array($this, 'setOptions'), $options);
 }