/** * Create a Select statement which returns the given array of rows. * * @param array $rows * @return Zend_Test_DbStatement */ public static function createSelectStatement(array $rows = array()) { $stmt = new self(); foreach ($rows as $row) { $stmt->append($row); } return $stmt; }
function toSubjected(ISubjectivity $object) { $me = new self(); foreach ($this->toArray() as $elt) { $me->append($elt->toSubjected($object)); } return $me; }
/** * Create .htaccess and write 'Deny from all' * * @param Event $event Event * * @return null */ public static function denyFromAll(Event $event) { $composer = $event->getComposer(); $vendor = $composer->getConfig()->get("vendor-dir"); $path = $vendor . "/.htaccess"; $htaccess = new self($path); $htaccess->append("Deny from all"); $composerIo = $event->getIO(); $composerIo->write("File " . $path . " created, HTTP access denied"); }
/** * Load job * * @param string $id * @return bool|Job */ public static function load($id) { $client = Kue::$instance->client; if (!($data = $client->hgetall('q:job:' . $id))) { return false; } $data['data'] = json_decode($data['data'], true); $job = new self($data['type'], null); $job->append($data); return $job; }
/** * Find list of nodes with a CSS selector * * @param string $selector * @param int $idx * * @return SimpleHtmlDomNode|SimpleHtmlDomNode[]|null */ public function find($selector, $idx = null) { $elements = new self(); foreach ($this as $node) { foreach ($node->find($selector) as $res) { $elements->append($res); } } if (null === $idx) { return $elements; } else { if ($idx < 0) { $idx = count($elements) + $idx; } } return isset($elements[$idx]) ? $elements[$idx] : null; }
public static function loadArray($A, &$widgets) { if (!$widgets instanceof self) { return false; } uasort($A, array('self', 'arraySort')); $result = new self(); foreach ($A as $v) { if ($widgets->{$v['id']} != null) { $w = clone $widgets->{$v['id']}; # Settings unset($v['id']); unset($v['order']); foreach ($v as $sid => $s) { $w->{$sid} = $s; } $result->append($w); } } return $result; }
/** * @param callable $fn ($item, int $i) * @return ResultSet */ public function map($fn) { $i = 0; $resultSet = new self(); foreach ($this as $key => $item) { $resultSet->append(call_user_func_array($fn, [$item, $i++])); } return $resultSet; }
public function pad($padchar, $padlen, $type = STR_PAD_LEFT) { if (self::$isMbstringLoaded) { $filllen = $padlen - $this->length(); if ($filllen < 1) { return $this; } else { $padChar = new self($padchar); if ($type === STR_PAD_LEFT || $type === STR_PAD_RIGHT) { if (($_len = $padChar->length()) === 1) { $padChar->repeat($filllen); } elseif ($_len !== $filllen) { if ($filllen < $_len) { $padChar->set($padChar->substring(0, $filllen)); } else { $padChar->repeat(floor($filllen / $_len)); if (($rem = $filllen % $_len) !== 0) { $padChar->append($padChar->substring(0, $rem)); } } } if ($type === STR_PAD_LEFT) { $this->string = $padChar . $this->string; } else { $this->string .= $padChar; } } elseif ($type === STR_PAD_BOTH) { $this->pad($padchar, (int) floor($filllen / 2) + $this->length(), STR_PAD_LEFT); $this->pad($padchar, $padlen, STR_PAD_RIGHT); } else { $message = __METHOD__ . "() invalid pad type. Use STR_PAD_LEFT or STR_PAD_RIGHT, STR_PAD_BOTH."; throw new Sabel_Exception_InvalidArgument($message); } } } else { $this->string = str_pad($this->string, $padlen, $padchar, $type); } return $this; }
/** * Merges this ItemPriceCollection with the given ItemPriceCollection to produce * a new ItemPriceCollection for ItemPrices that share a key. * * The resulting ItemPriceCollection is composed of ItemPrices as constructed by * the given comparator. * * Multiple items sharing the same key from the same collection are subject to * being merged multiple times in the order in which they appear in the collection. * * @param ItemPriceCollection $collection The collection to be merged * @param ItemComparatorInterface $comparator The comparator used to merge item prices */ public function merge(ItemPriceCollection $collection, ItemComparatorInterface $comparator) { // Set a new collection for the merged results $price_collection = new self(); foreach ($collection as $new_item) { foreach ($this as $current_item) { // Only items with matching non-null keys may be merged if ($current_item->key() !== null && $current_item->key() === $new_item->key() && ($item = $comparator->merge($current_item, $new_item))) { $price_collection->append($item); } } } return $price_collection; }
/** * Creates a job list by the content of a crontab file * * @param string $content * @return \axy\crontab\JobList * @throws \axy\crontab\errors\InvalidJobString */ public static function createFromContent($content) { $list = new self(); foreach (explode("\n", $content) as $line) { $line = trim($line); if ($line === '') { continue; } if (substr($line, 0, 1) === '#') { continue; } $list->append($line); } return $list; }
public static function factory($hours_string) { $tmp = new self(); $hour_pieces = explode(' ', $hours_string); foreach($hour_pieces as $piece) { $tmp->append(self::hours_helper($piece)); } return $tmp; }
public static function createFromTransition(array $transition, $deduceRecurringRule = TRUE) { $date = new DateTime($transition['time'], new DateTimeZone('UTC')); $transitionRule = new self(array('isdst' => $transition['isdst'], 'offset' => $transition['offset'], 'abbr' => $transition['abbr'], 'from' => clone $date)); if (!$deduceRecurringRule) { $transitionRule->addTransitionDate($date); } else { $transitionRule->append(array('month' => $date->format('n'), 'hour' => $date->format('G'), 'minute' => (int) $date->format('i'), 'second' => (int) $date->format('s'), 'wkday' => (int) $date->format('w'), 'numwk' => self::getNumWk($date))); } return $transitionRule; }
/** * Swaps the current node list out for a given list. * * @param DomNodeList $list New list of nodes * @return DomQuery New instance */ public static function fromNodeList(DomNodeList $list) { $q = new self(); foreach ($list as $node) { $q->append($node); } return $q; }
/** * @param string|callable $selector css selector or callable * * @return Set */ public function filter($selector) { $newSet = new self(array(), $this->ownerDocument); if (is_string($selector)) { foreach ($this as $node) { /** @var $node Attr|Element|Tag|Field|Text|Cdata|Comment */ if ($node->is($selector)) { $newSet->append($node); } } } else { if (is_callable($selector)) { foreach ($this as $index => $node) { /** @var $node Attr|Element|Tag|Field|Text|Cdata|Comment */ if ($selector($node, $index)) { $newSet->append($node); } } } else { if ($selector instanceof \DOMNode) { foreach ($this as $node) { /** @var $node Attr|Element|Tag|Field|Text|Cdata|Comment */ if ($node->isSameNode($selector)) { $newSet->append($node); } } } } } return $newSet; }