Exemplo n.º 1
0
 public function indexAction(ServerRequestInterface $Request, ResponseInterface $Response, callable $Next = null)
 {
     $data = [];
     // $path = $Request->getOriginalRequest()->getUri()->getPath();
     $pagdata = $this->getPaginationDataFromRequest($Request);
     $entities = $this->storage->fetchAll('page_templates');
     $cnt = count($entities);
     // If the requested page is later than the last, redirect to the last
     /*if ($cnt && $pagdata['page'] > $cnt) {
           return $Response
               ->withStatus(302)
               ->withHeader('Location', sprintf('%s?page-categories=%d', $path, $cnt));
       }*/
     $entities->setItemCountPerPage($pagdata['size']);
     $entities->setCurrentPageNumber($pagdata['page']);
     $data['page_templates'] = iterator_to_array($entities->getCurrentItems());
     // pagination data
     $data['pagination'] = [];
     $data['pagination']['page'] = $pagdata['page'];
     $data['pagination']['size'] = $pagdata['size'];
     $data['pagination']['count'] = $cnt;
     // return new JsonResponse($data);
     return new HtmlResponse($this->template->render('page/template::list', $data));
     // return new HtmlResponse($this->template->render('page::category-list', $data));
 }
 public function testIterator()
 {
     $violations = array(10 => $this->getViolation('Error 1'), 20 => $this->getViolation('Error 2'), 30 => $this->getViolation('Error 3'));
     $this->list = new ConstraintViolationList($violations);
     // indices are reset upon adding -> array_values()
     $this->assertSame(array_values($violations), iterator_to_array($this->list));
 }
Exemplo n.º 3
0
 /**
  * Create array of Sources from the given input directory.
  *
  * @param string $searchIn
  * @param string $outputTo
  * @return array
  */
 protected function findSources($searchIn, $outputTo)
 {
     $files = iterator_to_array(new FilesystemIterator($searchIn));
     return array_map(function (SplFileInfo $file) use($outputTo) {
         return $this->makeSource($file, $outputTo);
     }, $files);
 }
Exemplo n.º 4
0
 public function attributes($attributes)
 {
     if ($attributes instanceof \Traversable) {
         $attributes = iterator_to_array($attributes);
     }
     return implode('', array_map(array($this, 'attributesCallback'), array_keys($attributes), array_values($attributes)));
 }
Exemplo n.º 5
0
 public function metaform()
 {
     $value = $this->getValue();
     $data = $this->getData();
     $attributes = $this->getAttr();
     $form = array();
     $options = array();
     if (isset($data['options'])) {
         if (!is_admin()) {
             $new_options = array();
             foreach ($data['options'] as $key => $option) {
                 $tmp = $option['value'];
                 $option['value'] = $option['types-value'];
                 $option['types-value'] = $tmp;
                 $new_options[$key] = $option;
                 unset($tmp);
             }
             $data['options'] = $new_options;
         }
         foreach ($data['options'] as $key => $option) {
             $one_option_data = array('#value' => $option['value'], '#title' => stripslashes($option['title']));
             /**
              * add default value if needed
              * issue: frontend, multiforms CRED
              */
             //                if (array_key_exists('types-value', $option)) {
             //                    $one_option_data['#types-value'] = $option['types-value'];
             //                }
             $options[] = $one_option_data;
         }
     }
     /**
      * for user fields we reset title and description to avoid double
      * display
      */
     $title = $this->getTitle();
     if (empty($title)) {
         $title = $this->getTitle(true);
     }
     $options = apply_filters('wpt_field_options', $options, $title, 'select');
     /**
      * default_value
      */
     if (!empty($value) || $value == '0') {
         $data['default_value'] = $value;
     }
     $is_multiselect = array_key_exists('multiple', $attributes) && 'multiple' == $attributes['multiple'];
     $default_value = isset($data['default_value']) ? $data['default_value'] : null;
     //Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/189219391/comments
     if ($is_multiselect) {
         $default_value = new RecursiveIteratorIterator(new RecursiveArrayIterator($default_value));
         $default_value = iterator_to_array($default_value, false);
     }
     //##############################################################################################
     /**
      * metaform
      */
     $form[] = array('#type' => 'select', '#title' => $this->getTitle(), '#description' => $this->getDescription(), '#name' => $this->getName(), '#options' => $options, '#default_value' => $default_value, '#multiple' => $is_multiselect, '#validate' => $this->getValidationData(), '#class' => 'form-inline', '#repetitive' => $this->isRepetitive());
     return $form;
 }
Exemplo n.º 6
0
 public function process($args)
 {
     $answer = "";
     $args = trim($args);
     if (strlen($args) > 0) {
         $entrada = urlencode($args);
         $url = "https://www.google.com.mx/search?q={$entrada}&oq=200&aqs=chrome.1.69i57j69i59j69i65l2j0l2.3015j0j8&client=ubuntu-browser&sourceid=chrome&es_sm=122&ie=UTF-8";
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36');
         $html = curl_exec($ch);
         $web = new DomDocument();
         @$web->loadHTML($html);
         $nodos = @$web->getElementById('topstuff')->getElementsByTagName('div');
         $answer = "No pude convertir lo que me pides.";
         if ($nodos) {
             $nodos = iterator_to_array($nodos);
             if (count($nodos) === 6) {
                 $answer = utf8_decode($nodos[3]->nodeValue . " " . $nodos[4]->nodeValue);
             }
         }
     } else {
         $answer = "Ingresa una expresion.";
     }
     $this->reply($answer, $this->currentchannel, $this->nick);
 }
Exemplo n.º 7
0
 private function toStringRow($cells)
 {
     if ($cells instanceof \Traversable) {
         $cells = iterator_to_array($cells);
     }
     return implode($this->separator, $cells);
 }
 public function testItMapsTheConfigArrayToInflectorDefinitions()
 {
     $interface = 'example_interface';
     $methods = ['method1' => ['arg1', 'arg2']];
     $subject = new InflectorConfig([$interface => $methods]);
     assertEquals([new InflectorDefinition($interface, $methods)], iterator_to_array($subject));
 }
Exemplo n.º 9
0
 /**
  * Normalize all non-scalar data types (except null) in a string value
  *
  * @param mixed $value
  * @return mixed
  */
 protected function normalize($value)
 {
     if (is_scalar($value) || null === $value) {
         return $value;
     }
     // better readable JSON
     static $jsonFlags;
     if ($jsonFlags === null) {
         $jsonFlags = 0;
         $jsonFlags |= defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0;
         $jsonFlags |= defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0;
     }
     // Error suppression is used in several of these cases as a fix for each of
     // #5383 and #4616. Without it, #4616 fails whenever recursion occurs during
     // json_encode() operations; usage of a dedicated error handler callback
     // causes #5383 to fail when the Logger is being used as an error handler.
     // The only viable solution here is error suppression, ugly as it may be.
     if ($value instanceof DateTime) {
         $value = $value->format($this->getDateTimeFormat());
     } elseif ($value instanceof Traversable) {
         $value = @json_encode(iterator_to_array($value), $jsonFlags);
     } elseif (is_array($value)) {
         $value = @json_encode($value, $jsonFlags);
     } elseif (is_object($value) && !method_exists($value, '__toString')) {
         $value = sprintf('object(%s) %s', get_class($value), @json_encode($value));
     } elseif (is_resource($value)) {
         $value = sprintf('resource(%s)', get_resource_type($value));
     } elseif (!is_object($value)) {
         $value = gettype($value);
     }
     return (string) $value;
 }
Exemplo n.º 10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln("Fill...");
     $minCard = $input->getArgument('min');
     $maxCard = $input->getArgument('max');
     $seed = sha1(microtime() . rand() . $minCard . $maxCard);
     /* @var $progressBar \Symfony\Component\Console\Helper\ProgressHelper */
     $progressBar = $this->getHelper('progress');
     /* @var $repo \Trismegiste\Yuurei\Persistence\RepositoryInterface */
     $repo = $this->getContainer()->get('dokudoki.repository');
     $netizenList = iterator_to_array($repo->find(['-class' => 'netizen']), false);
     $netizenCount = count($netizenList);
     $query = ['-class' => ['$in' => ['small', 'picture', 'video', 'repeat', 'status']]];
     $pubCount = $repo->getCursor($query)->count();
     $progressBar->start($output, $pubCount);
     $cursor = $repo->find($query);
     /* @var $publish \Trismegiste\Socialist\Publishing */
     foreach ($cursor as $publish) {
         $commentaryCount = rand($minCard, $maxCard);
         for ($k = 0; $k < $commentaryCount; $k++) {
             /* @var $picked \Trismegiste\SocialBundle\Security\Netizen */
             $picked = $netizenList[rand(0, $netizenCount - 1)];
             $comment = new \Trismegiste\Socialist\Commentary($picked->getAuthor());
             $comment->setMessage("This is a commentary ({$seed}) to fill the database for benchmark purpose");
             foreach ($picked->getFanIterator() as $fan => $dummy) {
                 $tmpAuth = new \Trismegiste\Socialist\Author($fan);
                 $comment->addFan($tmpAuth);
             }
             $publish->attachCommentary($comment);
         }
         $repo->persist($publish);
         $progressBar->advance();
     }
     $progressBar->finish();
 }
Exemplo n.º 11
0
 public function getWordsTw()
 {
     //$tweetSearch=$this->barredoraTw->tweetSearch;
     $db = $this->database;
     $tags = iterator_to_array($db->selectCollection('tweetSearch')->find()->sort(array('UScreatedAt' => -1))->limit(50));
     return $tags;
 }
Exemplo n.º 12
0
 /**
  * Emulates changing of directory name.
  *
  * @param string $path
  * @param string $newPath
  *
  * @return bool
  */
 public function renameDirectory($path, $newPath)
 {
     $sourcePath = $this->applyPathPrefix(rtrim($path, '/') . '/');
     $objectsIterator = $this->client->getIterator('listObjects', ['Bucket' => $this->bucket, 'Prefix' => $sourcePath]);
     $objects = array_filter(iterator_to_array($objectsIterator), function ($v) {
         return isset($v['Key']);
     });
     if (!empty($objects)) {
         /* @var OperationManager $operation */
         $operation = $this->app['operation'];
         $operation->start();
         $total = count($objects);
         $current = 0;
         foreach ($objects as $entry) {
             $this->client->copyObject(array('Bucket' => $this->bucket, 'Key' => $this->replacePath($entry['Key'], $path, $newPath), 'CopySource' => urlencode($this->bucket . '/' . $entry['Key'])));
             if ($operation->isAborted()) {
                 // Delete target folder in case if operation was aborted
                 $targetPath = $this->applyPathPrefix(rtrim($newPath, '/') . '/');
                 $this->client->deleteMatchingObjects($this->bucket, $targetPath);
                 return true;
             }
             $operation->updateStatus(array('total' => $total, 'current' => ++$current));
         }
         $this->client->deleteMatchingObjects($this->bucket, $sourcePath);
     }
     return true;
 }
Exemplo n.º 13
0
 public function testMustNotTerminateWithTraversable()
 {
     $traversable = simplexml_load_string('<root><foo/><foo/><foo/></root>')->foo;
     $chunked = new ChunkedIterator($traversable, 2);
     $actual = iterator_to_array($chunked, false);
     $this->assertCount(2, $actual);
 }
Exemplo n.º 14
0
 /**
  * Normalize all non-scalar data types (except null) in a string value
  *
  * @param mixed $value
  * @return mixed
  */
 protected function flatten($value)
 {
     if (is_scalar($value) || null === $value) {
         return $value;
     }
     // better readable JSON
     static $jsonFlags;
     if ($jsonFlags === null) {
         $jsonFlags = 0;
         $jsonFlags |= defined('JSON_UNESCAPED_SLASHES') ? JSON_UNESCAPED_SLASHES : 0;
         $jsonFlags |= defined('JSON_UNESCAPED_UNICODE') ? JSON_UNESCAPED_UNICODE : 0;
     }
     if ($value instanceof \DateTime) {
         $value = $value->format($this->getDateTimeFormat());
     } elseif ($value instanceof \Traversable) {
         $value = json_encode(iterator_to_array($value), $jsonFlags);
     } elseif (is_array($value)) {
         $value = json_encode($value, $jsonFlags);
     } elseif (is_object($value) && !method_exists($value, '__toString')) {
         $value = sprintf('object(%s) %s', get_class($value), json_encode($value));
     } elseif (is_resource($value)) {
         $value = sprintf('resource(%s)', get_resource_type($value));
     } elseif (!is_object($value)) {
         $value = gettype($value);
     }
     return (string) $value;
 }
Exemplo n.º 15
0
 /**
  * Sets default option values for this instance
  *
  * @param array|\Traversable $options
  */
 public function __construct($options = array())
 {
     if ($options instanceof Traversable) {
         $options = iterator_to_array($options);
     } elseif (!is_array($options)) {
         $options = func_get_args();
         $temp['uriHandler'] = array_shift($options);
         if (!empty($options)) {
             $temp['allowRelative'] = array_shift($options);
         }
         if (!empty($options)) {
             $temp['allowAbsolute'] = array_shift($options);
         }
         $options = $temp;
     }
     if (isset($options['uriHandler'])) {
         $this->setUriHandler($options['uriHandler']);
     }
     if (isset($options['allowRelative'])) {
         $this->setAllowRelative($options['allowRelative']);
     }
     if (isset($options['allowAbsolute'])) {
         $this->setAllowAbsolute($options['allowAbsolute']);
     }
     parent::__construct($options);
 }
Exemplo n.º 16
0
    /**
     * __construct(): defined by Route interface.
     *
     * @see    Route::__construct()
     * @param  mixed $options
     * @return void
     */
    public function __construct($options = null)
    {
        parent::__construct($options);
        
        if ($options instanceof Config) {
            $options = $options->toArray();
        } elseif ($options instanceof Traversable) {
            $options = iterator_to_array($options);
        }

        if (!is_array($options)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Expected an array or Traversable; received "%s"',
                (is_object($options) ? get_class($options) : gettype($options))
            ));
        }
        
        if (!isset($options['route']) || !$options['route'] instanceof Route) {
            throw new Exception\InvalidArgumentException('Route not defined or not an instance of Route');
        }

        $this->route        = $options['route'];
        $this->mayTerminate = (isset($options['may_terminate']) && $options['may_terminate']);
        
        if (isset($options['child_routes'])) {
            $this->childRoutes = $options['child_routes'];
        }
    }
Exemplo n.º 17
0
 protected function assertOrderedIterator($expected, \Traversable $iterator)
 {
     $values = array_map(function (HandlerInterface $handler) {
         return $handler->getPath();
     }, iterator_to_array($iterator));
     $this->assertEquals($expected, array_values($values));
 }
Exemplo n.º 18
0
 /**
  * @static
  * @param $iterator
  * @param bool $recursive
  * @return array
  * @throws Exception
  */
 public static function iteratorToArray($iterator, $recursive = true)
 {
     if (!is_array($iterator) && !$iterator instanceof Traversable) {
         throw new Exception(__METHOD__ . ' expects an array or Traversable object');
     }
     if (!$recursive) {
         if (is_array($iterator)) {
             return $iterator;
         }
         return iterator_to_array($iterator);
     }
     if (method_exists($iterator, 'toArray')) {
         return $iterator->toArray();
     }
     $array = array();
     foreach ($iterator as $key => $value) {
         if (is_scalar($value)) {
             $array[$key] = $value;
             continue;
         }
         if ($value instanceof Traversable) {
             $array[$key] = static::iteratorToArray($value, $recursive);
             continue;
         }
         if (is_array($value)) {
             $array[$key] = static::iteratorToArray($value, $recursive);
             continue;
         }
         $array[$key] = $value;
     }
     return $array;
 }
Exemplo n.º 19
0
 /**
  * Constructor
  *
  * We used the Adapter instead of Zend\Db for a performance reason.
  *
  * @param Adapter|array|Traversable $db
  * @param string $tableName
  * @param array $columnMap
  * @param string $separator
  * @throws Exception\InvalidArgumentException
  */
 public function __construct($db, $tableName = null, array $columnMap = null, $separator = null)
 {
     if ($db instanceof Traversable) {
         $db = iterator_to_array($db);
     }
     if (is_array($db)) {
         parent::__construct($db);
         $separator = isset($db['separator']) ? $db['separator'] : null;
         $columnMap = isset($db['column']) ? $db['column'] : null;
         $tableName = isset($db['table']) ? $db['table'] : null;
         $db = isset($db['db']) ? $db['db'] : null;
     }
     if (!$db instanceof Adapter) {
         throw new Exception\InvalidArgumentException('You must pass a valid Zend\\Db\\Adapter\\Adapter');
     }
     $tableName = (string) $tableName;
     if ('' === $tableName) {
         throw new Exception\InvalidArgumentException('You must specify a table name. Either directly in the constructor, or via options');
     }
     $this->db = $db;
     $this->tableName = $tableName;
     $this->columnMap = $columnMap;
     if (!empty($separator)) {
         $this->separator = $separator;
     }
     $this->setFormatter(new DbFormatter());
 }
Exemplo n.º 20
0
    /**
     * Constructor
     * 
     * @param array $data
     * @param object $adapter 
     */
    public function __construct($data, $adapter = null) 
    {
        if (is_object($data)) {
            if (method_exists($data, 'toArray')) {
                $data= $data->toArray();
            } elseif ($data instanceof \Traversable) {
                $data = iterator_to_array($data);
            }
        }
        
        if (empty($data) || !is_array($data)) {
            throw new Exception\InvalidArgumentException('You must pass an array of parameters');
        }

        foreach ($this->attributeRequired as $key) {
            if (empty($data[$key])) {
                throw new Exception\InvalidArgumentException(sprintf(
                    'The param "%s" is a required parameter for class %s',
                    $key,
                    __CLASS__
                ));
            }
        }

        $this->attributes = $data;
        $this->adapter    = $adapter;
    }
Exemplo n.º 21
0
 public function visit(\DOMAttr $att, Compiler $context)
 {
     $node = $att->ownerElement;
     $pi = $context->createControlNode("set __tmp_omit = " . html_entity_decode($att->value));
     $node->parentNode->insertBefore($pi, $node);
     $pi = $context->createControlNode("if not __tmp_omit");
     $node->parentNode->insertBefore($pi, $node);
     $pi = $context->createControlNode("endif");
     if ($node->firstChild) {
         $node->insertBefore($pi, $node->firstChild);
     } else {
         $node->appendChild($pi);
     }
     $pi = $context->createControlNode("if not __tmp_omit");
     $node->appendChild($pi);
     $pi = $context->createControlNode("endif");
     if ($node->parentNode->nextSibling) {
         $node->parentNode->insertBefore($pi, $node->parentNode->nextSibling);
     } else {
         $node->parentNode->appendChild($pi);
     }
     $node->removeAttributeNode($att);
     if ($att->value == "true" || $att->value == "1") {
         foreach (iterator_to_array($node->attributes) as $att) {
             $node->removeAttributeNode($att);
         }
     }
     return Attribute::STOP_ATTRIBUTE;
 }
Exemplo n.º 22
0
 protected function getFiles()
 {
     $files = array('LICENSE', 'vendor/autoload.php', 'Goutte/Client.php', 'vendor/guzzle/http/Guzzle/Http/Resources/cacert.pem', 'vendor/guzzle/http/Guzzle/Http/Resources/cacert.pem.md5');
     $dirs = array('vendor/composer', 'vendor/symfony', 'vendor/guzzle');
     $iterator = Finder::create()->files()->name('*.php')->in($dirs);
     return array_merge($files, iterator_to_array($iterator));
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function getFunctions()
 {
     $compiler = function () {
         throw new LogicException('Compilation not supported.');
     };
     return [new ExpressionFunction('url', $compiler, function ($arguments, $url) {
         return $url;
     }), new ExpressionFunction('link', $compiler, function ($arguments, $selector) {
         return $arguments['_crawler']->selectLink($selector);
     }), new ExpressionFunction('button', $compiler, function ($arguments, $selector) {
         return $arguments['_crawler']->selectButton($selector);
     }), new ExpressionFunction('status_code', $compiler, function ($arguments) {
         return $arguments['_response']->getStatusCode();
     }), new ExpressionFunction('headers', $compiler, function ($arguments) {
         $headers = [];
         foreach ($arguments['_response']->getHeaders() as $key => $value) {
             $headers[$key] = $value[0];
         }
         return $headers;
     }), new ExpressionFunction('body', $compiler, function ($arguments) {
         return (string) $arguments['_response']->getBody();
     }), new ExpressionFunction('header', $compiler, function ($arguments, $name) {
         $name = str_replace('_', '-', strtolower($name));
         if (!$arguments['_response']->hasHeader($name)) {
             return;
         }
         return $arguments['_response']->getHeader($name)[0];
     }), new ExpressionFunction('scalar', $compiler, function ($arguments, $scalar) {
         return $scalar;
     }), new ExpressionFunction('join', $compiler, function ($arguments, $value, $glue) {
         if ($value instanceof \Traversable) {
             $value = iterator_to_array($value, false);
         }
         return implode($glue, (array) $value);
     }), new ExpressionFunction('fake', $compiler, function ($arguments, $provider) {
         $arguments = func_get_args();
         return $this->faker->format($provider, array_splice($arguments, 2));
     }), new ExpressionFunction('regex', $compiler, function ($arguments, $regex) {
         $ret = @preg_match($regex, (string) $arguments['_response']->getBody(), $matches);
         if (false === $ret) {
             throw new InvalidArgumentException(sprintf('Regex "%s" is not valid: %s.', $regex, error_get_last()['message']));
         }
         return isset($matches[1]) ? $matches[1] : null;
     }), new ExpressionFunction('css', $compiler, function ($arguments, $selector) {
         if (null === $arguments['_crawler']) {
             throw new LogicException(sprintf('Unable to get "%s" CSS selector as the page is not crawlable.', $selector));
         }
         return $arguments['_crawler']->filter($selector);
     }), new ExpressionFunction('xpath', $compiler, function ($arguments, $selector) {
         if (null === $arguments['_crawler']) {
             throw new LogicException(sprintf('Unable to get "%s" XPATH selector as the page is not crawlable.', $selector));
         }
         return $arguments['_crawler']->filterXPath($selector);
     }), new ExpressionFunction('json', $compiler, function ($arguments, $selector) {
         if (null === ($data = json_decode((string) $arguments['_response']->getBody(), true))) {
             throw new LogicException(sprintf(' Unable to get the "%s" JSON path as the Response body does not seem to be JSON.', $selector));
         }
         return JmesPath::search($selector, $data);
     })];
 }
Exemplo n.º 24
0
 public function items(ItemsEvent $event)
 {
     if (!class_exists('Eccube\\Doctrine\\ORM\\Tools\\Pagination\\Paginator')) {
         return;
     }
     if (!$event->target instanceof Query) {
         return;
     }
     $event->stopPropagation();
     $useOutputWalkers = false;
     if (isset($event->options['wrap-queries'])) {
         $useOutputWalkers = $event->options['wrap-queries'];
     }
     $event->target->setFirstResult($event->getOffset())->setMaxResults($event->getLimit())->setHint(CountWalker::HINT_DISTINCT, $event->options['distinct']);
     $fetchJoinCollection = true;
     if ($event->target->hasHint(self::HINT_FETCH_JOIN_COLLECTION)) {
         $fetchJoinCollection = $event->target->getHint(self::HINT_FETCH_JOIN_COLLECTION);
     }
     $paginator = new Paginator($event->target, $fetchJoinCollection);
     $paginator->setUseOutputWalkers($useOutputWalkers);
     if (($count = $event->target->getHint(QuerySubscriber::HINT_COUNT)) !== false) {
         $event->count = intval($count);
     } else {
         $event->count = count($paginator);
     }
     $event->items = iterator_to_array($paginator);
 }
Exemplo n.º 25
0
 /**
  * Returns sring representation of object.
  *
  * @return string
  */
 public function __toString()
 {
     $labels = array_map(function ($basket) {
         return $basket->getName();
     }, iterator_to_array($this->baskets));
     return implode(', ', $labels);
 }
Exemplo n.º 26
0
 public function handle()
 {
     $dirs = iterator_to_array(Finder::create()->in($this->repo->releasePath())->depth(0)->sortByChangedTime());
     foreach (array_slice(array_reverse($dirs), 3) as $dir) {
         $this->fs()->deleteDirectory($dir);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function readEntry($path, $locale, array $indices, $fallback = true)
 {
     $data = $this->reader->read($path, $locale);
     $entry = RecursiveArrayAccess::get($data, $indices);
     $multivalued = is_array($entry) || $entry instanceof \Traversable;
     if (!($fallback && (null === $entry || $multivalued))) {
         return $entry;
     }
     if (null !== ($fallbackLocale = $this->getFallbackLocale($locale))) {
         $parentEntry = $this->readEntry($path, $fallbackLocale, $indices, true);
         if ($entry || $parentEntry) {
             $multivalued = $multivalued || is_array($parentEntry) || $parentEntry instanceof \Traversable;
             if ($multivalued) {
                 if ($entry instanceof \Traversable) {
                     $entry = iterator_to_array($entry);
                 }
                 if ($parentEntry instanceof \Traversable) {
                     $parentEntry = iterator_to_array($parentEntry);
                 }
                 $entry = array_merge($parentEntry ?: array(), $entry ?: array());
             } else {
                 $entry = null === $entry ? $parentEntry : $entry;
             }
         }
     }
     return $entry;
 }
Exemplo n.º 28
0
 /**
  * @expectedException \RuntimeException
  */
 public function testValidatesEachElement()
 {
     $c = new Client();
     $requests = ['foo'];
     $t = new TransactionIterator(new \ArrayIterator($requests), $c, []);
     iterator_to_array($t);
 }
Exemplo n.º 29
0
 /**
  * Constructor
  * 
  * @param  Adapter $adapter
  * @param  array $data 
  * @return void
  */
 public function __construct($adapter, $data = null)
 {
     if (!$adapter instanceof Zend_Cloud_Infrastructure_Adapter) {
         #require_once 'Zend/Cloud/Infrastructure/Exception.php';
         throw new Zend_Cloud_Infrastructure_Exception("You must pass a Zend_Cloud_Infrastructure_Adapter instance");
     }
     if (is_object($data)) {
         if (method_exists($data, 'toArray')) {
             $data = $data->toArray();
         } elseif ($data instanceof Traversable) {
             $data = iterator_to_array($data);
         }
     }
     if (empty($data) || !is_array($data)) {
         #require_once 'Zend/Cloud/Infrastructure/Exception.php';
         throw new Zend_Cloud_Infrastructure_Exception("You must pass an array of parameters");
     }
     foreach ($this->attributeRequired as $key) {
         if (empty($data[$key])) {
             #require_once 'Zend/Cloud/Infrastructure/Exception.php';
             throw new Zend_Cloud_Infrastructure_Exception(sprintf('The param "%s" is a required param for %s', $key, __CLASS__));
         }
     }
     $this->adapter = $adapter;
     $this->attributes = $data;
 }
Exemplo n.º 30
0
 public final function convert($element)
 {
     if ($element instanceof Iterator) {
         return iterator_to_array($this->convertList($element));
     }
     return $this->convertSingle($element);
 }