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


PHP Collection::append方法代码示例

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


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

示例1: scrape

 /**
  * Scrape URL and collect output
  * @param string $url
  * @param OutputInterface $output
  */
 public function scrape($url, OutputInterface $output)
 {
     $this->collection->exchangeArray([]);
     try {
         $initialPage = $this->client->get($url)->send();
     } catch (BadResponseException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         throw new \RuntimeException('Unable to load initial page');
     }
     $xml = $this->getSimpleXml($initialPage->getBody());
     $items = $xml->xpath($this->config['collection']);
     foreach ($items as $item) {
         $title = $item->xpath($this->config['title']);
         $unitPrice = $item->xpath($this->config['unitPrice']);
         $itemUrl = $item->xpath($this->config['itemUrl']);
         $itemSize = 0;
         $itemDesc = null;
         if (isset($itemUrl[0]->attributes()['href'])) {
             try {
                 $itemPage = $this->client->get((string) $itemUrl[0]->attributes()['href'])->send();
                 $itemPageBody = $this->getSimpleXml($itemPage->getBody());
                 $itemSize = $itemPage->getContentLength();
                 $itemDesc = $itemPageBody->xpath($this->config['desc']);
             } catch (BadResponseException $e) {
                 $output->writeln('<error>' . $e->getMessage() . '</error>');
             }
         }
         if ($title && $unitPrice) {
             $parsedPrice = (double) \trim(\str_replace('&pound', null, $unitPrice[0]));
             $this->collection->append(['title' => \trim($title[0]), 'unit_price' => $parsedPrice, 'description' => \trim($itemDesc[0]), 'size' => \round($itemSize / 1024) . 'kb']);
         }
     }
     return $this->collection;
 }
开发者ID:pharman,项目名称:Test,代码行数:39,代码来源:Scraper.php

示例2: buildCollection

 public static function buildCollection($filters, $order = null)
 {
     // filters must be field=>value
     $collection = new Collection();
     $sql = $params = array();
     foreach ($filters as $key => $filter) {
         if (!is_array($filter)) {
             $params[":{$key}"] = $filter;
             $sql[] = "`{$key}` = :{$key}";
         } else {
             $params[":{$key}"] = $filter['value'];
             $sql[] = "`{$key}` {$filter['operator']} :{$key}";
         }
     }
     if ($sql) {
         $sql = "WHERE " . implode(' AND ', $sql);
     } else {
         $sql = '';
     }
     $sql = "SELECT * FROM `" . static::TABLE_NAME . "` {$sql}";
     $stmt = static::getConnection()->prepAndExecute(new \ArtfulRobot\PDO_Query("Fetch records from " . static::TABLE_NAME, $sql, $params));
     if ($stmt->errorCode() != '00000') {
         throw new Exception("PDO error: " . print_r($stmt->errorInfo(), 1));
     }
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         // create an object of the class
         $obj = new static();
         $obj->loadFromArray($row, false, self::CAST_DB);
         // these lines differ from main code
         $id = implode("\\A", $obj->getPK());
         $collection->append($obj, $id);
         unset($obj);
     }
     return $collection;
 }
开发者ID:artfulrobot,项目名称:artfulrobot,代码行数:35,代码来源:ModelMultiplePK.php

示例3: append

 /**
  * Appends the specified element to the end of this collection.
  * @param  mixed
  * @return void
  * @throws \Nette\InvalidArgumentException
  */
 public function append($item)
 {
     // collection was not loaded before, now it is only manualy set collection
     if (!$this->isLoaded()) {
         $this->loadable = false;
     }
     return parent::append($item);
 }
开发者ID:matak,项目名称:dbrecord,代码行数:14,代码来源:LazyCollection.php

示例4: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     static::$collection = new Collection();
     static::$collection->append('part1', ['item1' => 'stuff']);
     static::$collection->freeze('*');
     static::assertTrue(static::$collection->immutable('part1'));
     static::$collection->thaw('*');
     static::assertFalse(static::$collection->immutable('part1'));
 }
开发者ID:anctemarry27,项目名称:cogs,代码行数:9,代码来源:CollectionTest.php

示例5: toCollection

 /**
  * Converts this iterator into an instance of Morph_Collection
  *
  * Note that this means all objects will be held in memory so
  * you need to be a bit careful not to exceed memory limits
  *
  * @return Morph_Collection
  */
 public function toCollection()
 {
     $collection = new Collection();
     $collection->setPermissableType(\get_class($this->type));
     $collection->setTotalCount($this->totalCount());
     $this->rewind();
     foreach ($this as $object) {
         $collection->append($object);
     }
     return $collection;
 }
开发者ID:rmsy,项目名称:opentrackr,代码行数:19,代码来源:Iterator.php

示例6: add

 /**
  * @param ResourceInterface $resource
  * @return $this
  */
 public function add(ResourceInterface $resource)
 {
     $filename = $resource->getFilename();
     if (in_array($filename, $this->resources)) {
         // skip duplicates
         return $this;
     }
     $this->resources[] = $filename;
     $resource->setAssetsRevision($this->assetsRevision);
     $this->collection->append($resource);
     return $this;
 }
开发者ID:serebro,项目名称:assets-manager,代码行数:16,代码来源:Manager.php

示例7: buildCollection

 /**
  * build a Collection object with objects of this class based on filters
  *
  * @param Array $filters
  * @param string|null $order literal SQL appended to "ORDER BY " if used.
  * @returns Collection object
  */
 public static function buildCollection($filters, $order = null)
 {
     Debug::log(">>" . get_called_class() . ":: " . __FUNCTION__ . " called with filters:", $filters);
     $collection = new Collection();
     $sql = static::buildCollectionSql($params, $filters, $order);
     $stmt = static::getConnection()->prepAndExecute(new \ArtfulRobot\PDO_Query("Fetch records from " . static::TABLE_NAME, $sql, $params));
     if ($stmt->errorCode() != '00000') {
         throw new Exception("PDO error: " . print_r($stmt->errorInfo(), 1));
     }
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         // create an object of the class
         $obj = new static();
         $obj->loadFromArray($row, false, self::CAST_DB);
         $collection->append($obj, $obj->id);
         unset($obj);
     }
     Debug::log("<< Returning collection with " . $collection->count() . " entries");
     return $collection;
 }
开发者ID:artfulrobot,项目名称:artfulrobot,代码行数:26,代码来源:Model.php

示例8: children

 /**
  * Return a collection of subfolders
  * 
  * @param array $ignore
  * @param boolean $plain
  * @return Collection
  */
 public function children($ignore = null, $plain = false)
 {
     $raw = $this->scan($ignore);
     if ($plain) {
         $content = array();
         foreach ($raw as $file) {
             if (is_dir($this->root . DS . $file)) {
                 $content[] = $file;
             }
         }
     } else {
         $content = new Collection();
         foreach ($raw as $file) {
             if (is_dir($this->root . DS . $file)) {
                 $content->append($file, new static($this->root . DS . $file));
             }
         }
     }
     return $content;
 }
开发者ID:LucasFyl,项目名称:korakia,代码行数:27,代码来源:folder.php

示例9: append

 public function append($value)
 {
     $this->collection->append($value);
     parent::append($value);
     $this->refreshPositions();
 }
开发者ID:disider,项目名称:Propel2,代码行数:6,代码来源:CollectionIterator.php

示例10: files

 public function files()
 {
     $files = new Collection();
     foreach ($this->data as $page) {
         foreach ($page->files() as $file) {
             $files->append($page->id() . '/' . strtolower($file->filename()), $file);
         }
     }
     return $files;
 }
开发者ID:kristianhalte,项目名称:super_organic,代码行数:10,代码来源:pages.php


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