Exemple #1
0
 public function test_without_starter__extensions()
 {
     $projectNamespace = $this->getProjectClass('WithoutStarter');
     $app = (new \Staq\Server())->addApplication($projectNamespace, '/')->addPlatform('local')->getCurrentApplication();
     $expected = $this->appendProjectNamespace('WithoutStarter');
     \UArray::doRemoveValue($expected, 'Staq\\App\\Starter');
     $this->assertEquals($expected, $app->getExtensionNamespaces());
 }
Exemple #2
0
 public function test_without_starter__extensions()
 {
     $projectNamespace = $this->getProjectClass('WithoutStarter');
     $app = \Staq\App::create($projectNamespace)->setPlatform('local');
     $expected = $this->appendProjectNamespace('WithoutStarter');
     \UArray::doRemoveValue($expected, 'Staq\\App\\Starter');
     $this->assertEquals($expected, $app->getExtensionNamespaces());
 }
Exemple #3
0
 public function fetchByField($field, $value, $limit = NULL)
 {
     $models = $this->fetchAll();
     \UArray::doFilterBy($models, $field, $value);
     if ($limit) {
         $models = array_slice($models, 0, $limit);
     }
     return $models;
 }
Exemple #4
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;
 }
Exemple #5
0
 protected function groupArticles($articles, $index)
 {
     \UArray::doGroupBy($articles, $index);
     foreach ($articles as $key => $groupedArticles) {
         $articles[$key] = [];
         $articles[$key]['id'] = \UString::stripSpecialChar($key);
         $articles[$key]['name'] = $key;
         $articles[$key]['articles'] = $groupedArticles;
     }
     return $articles;
 }
Exemple #6
0
 public function set($map)
 {
     \UArray::convertToArray($map);
     $result = [];
     foreach ($map as $key => $item) {
         $validation = $this->formatItemSeed($item, $key);
         if ($validation) {
             $result[$key] = $item;
         }
     }
     $this->seed = json_encode($result);
     $this->map = $map;
     return $this;
 }
Exemple #7
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;
 }
Exemple #8
0
 protected function addVariables()
 {
     parent::addVariables();
     $groupModelTypes = (new \Stack\Setting())->parse('BackOffice')->get('model');
     foreach ($groupModelTypes as $group => $modelTypes) {
         if (!is_array($modelTypes)) {
             if (empty($modelTypes)) {
                 unset($groupModelTypes[$group]);
             } else {
                 \UArray::doRenameKey($groupModelTypes, $group, $modelTypes);
                 $groupModelTypes[$modelTypes] = [$modelTypes];
             }
         }
     }
     $this['groupModelTypes'] = $groupModelTypes;
 }
Exemple #9
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;
 }
Exemple #10
0
<?php

if (!isset($contents)) {
    $contents = \UArray::convertToArray($content);
}
echo PHP_EOL;
echo 'Files' . PHP_EOL;
echo '---------' . PHP_EOL;
foreach ($contents as $name => $content) {
    if (!is_numeric($name)) {
        echo '; ' . $name . PHP_EOL;
    }
    echo $content . PHP_EOL;
    echo PHP_EOL;
}
echo PHP_EOL;
echo 'Result parsing' . PHP_EOL;
echo '---------' . PHP_EOL;
print_r($result->toArray());
Exemple #11
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;
                 }
             }
         }
     }
 }
Exemple #12
0
 protected function initFetchValues()
 {
     foreach ($this->inputs as $input) {
         $population = $this->getPopulation($input->populationType);
         if (\UArray::hasDeepSelector($population, $input->address)) {
             $input->isActive = TRUE;
             $input->fetchValue = \UArray::getDeepSelector($population, $input->address);
         }
     }
 }
Exemple #13
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;
 }
Exemple #14
0
 public static function doMergeRecursive(&$reference, $append)
 {
     foreach ($append as $key => $value) {
         if (isset($reference[$key])) {
             if (is_array($reference[$key]) && is_array($value)) {
                 $reference[$key] = \UArray::mergeRecursive($reference[$key], $value);
             } else {
                 if (is_numeric($key)) {
                     $reference[] = $value;
                 } else {
                     $reference[$key] = $value;
                 }
             }
         } else {
             $reference[$key] = $value;
         }
     }
 }
Exemple #15
0
 public function offsetUnset($index)
 {
     if (!$this->has($index)) {
         $this->undefinedIndexAcces($index);
         return NULL;
     }
     if ($this->deepSelectorOption) {
         $new_array = \UArray::unsetDeepSelector($this->getArrayCopy(), $index);
         $this->exchangeArray($new_array);
     } else {
         parent::offsetUnset($index);
     }
 }
Exemple #16
0
 public function test_do_reverse_merge_unique__three()
 {
     $merged = array(1, 2, 3);
     \UArray::doReverseMergeUnique($merged, array(2, 3, 4), array(5, 2));
     $this->assertEquals(array(1, 3, 4, 5, 2), $merged);
 }
Exemple #17
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;
 }
Exemple #18
0
 public function fetchIdsByRelatedThroughTable($table, $field, $relatedField, $related, $filterList = [])
 {
     if (!$related->exists()) {
         return array();
     }
     $sql = 'SELECT ' . $field . ' FROM ' . $table . ' WHERE ' . $relatedField . '=' . $related->id;
     foreach ($filterList as $key => $value) {
         $sql .= ' AND ' . $key . '=' . $value;
     }
     $request = new Request($sql);
     $existing = $request->execute();
     return array_keys(\UArray::keyBy($existing, $field));
 }