本文整理汇总了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('£', 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;
}
示例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;
}
示例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);
}
示例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'));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例9: append
public function append($value)
{
$this->collection->append($value);
parent::append($value);
$this->refreshPositions();
}
示例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;
}