/** * @return MoodlePluginCollection */ public function sortByDependencies() { $elements = []; foreach ($this->items as $item) { $elements[$item->getComponent()] = []; } // Loop through a second time, only adding dependencies that exist in our list. foreach ($this->items as $item) { $dependencies = $item->getDependencies(); foreach ($dependencies as $dependency) { if (array_key_exists($dependency, $elements)) { $elements[$item->getComponent()][] = $dependency; } } } $sorter = new StringSort($elements); $results = $sorter->sort(); $sorted = new self(); foreach ($results as $result) { foreach ($this->items as $item) { if ($result === $item->getComponent()) { $sorted->add($item); break; } } } if ($this->count() !== $sorted->count()) { throw new \LogicException('The sorted list of plugins does not match the size of original list'); } return $sorted; }
/** * This method loads all available test suites for PHPUnit * * @return PHPUnit_Framework_TestSuite */ public static function suite() { $groups = Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_GROUPS); $modules = Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_MODULES); $testSuiteClass = EcomDev_Utils_Reflection::getReflection((string) Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_SUITE)); if (!$testSuiteClass->isSubclassOf('EcomDev_PHPUnit_Test_Suite_Group')) { new RuntimeException('Test Suite class should be extended from EcomDev_PHPUnit_Test_Suite_Group'); } $suite = new self('Magento Test Suite'); // Walk through different groups in modules for finding test cases foreach ($groups->children() as $group) { foreach ($modules->children() as $module) { $realModule = Mage::getConfig()->getNode('modules/' . $module->getName()); if (!$realModule || !$realModule->is('active')) { $suite->addTest(self::warning('There is no module with name: ' . $module->getName())); continue; } $moduleCodeDir = Mage::getBaseDir('code') . DS . (string) $realModule->codePool; $searchPath = Mage::getModuleDir('', $module->getName()) . DS . 'Test' . DS . (string) $group; if (!is_dir($searchPath)) { continue; } $currentGroups = array($group->getName(), $module->getName()); $testCases = self::_loadTestCases($searchPath, $moduleCodeDir); foreach ($testCases as $className) { $suite->addTest($testSuiteClass->newInstance($className, $currentGroups)); } } } if (!$suite->count()) { $suite->addTest(self::warning('There were no test cases for the current run')); } return $suite; }
/** * Dynamically retrieve attributes on the model. * * @param string $key * * @return mixed */ public function __get($key) { $newCollection = new self(); foreach ($this->items as $item) { if ($item instanceof self) { // This item is a collection. foreach ($item as $subItem) { $newCollection->put($newCollection->count(), $subItem->{$key}); } } elseif (is_object($item) && !$item instanceof self && $item->{$key} instanceof self) { // Next tap is a collection. foreach ($item->{$key} as $subItem) { $newCollection->put($newCollection->count(), $subItem); } } else { // This item is an object. $newCollection->put($newCollection->count(), $item->{$key}); } } return $newCollection; }
public static function parse(Tag $word_list) { $result = array(); foreach ($word_list->in("word") as $word) { $obj = new self(); $obj->count($word->f("count.value()")); $obj->surface($word->f("surface.value()")); $obj->reading($word->f("reading.value()")); $obj->pos($word->f("pos.value()")); $result[] = $obj; } return $result; }
public static function byName($name) { $niceName = str_replace('_', ' ', $name); $settings = new self(); $settings->addFilter(new Ajde_Filter_Join('setting_meta', 'setting_meta.setting', 'setting.id')); $settings->addFilter(new Ajde_Filter_Join('meta', 'meta.id', 'setting_meta.meta')); $settings->addFilter(new Ajde_Filter_Where('setting.name', Ajde_Filter::FILTER_EQUALS, $niceName)); $settings->getQuery()->addSelect('setting_meta.value'); $settings->getQuery()->addSelect('meta.name AS meta_name'); $result = []; if ($settings->count()) { foreach ($settings as $setting) { $result[$setting->meta_name] = $setting->value; } } return $result; }
/** * ( excerpt from http://php.net/manual/en/splfixedarray.fromarray.php ) * * Import the PHP array array in a new SplFixedArray instance * * @array mixed The array to import. * @save_indexes * mixed Try to save the numeric indexes used in the original * array. * * @return mixed Returns an instance of SplFixedArray containing the * array content. */ public static function fromArray($array, $save_indexes = true) { $fixed_array = new self(); if ($save_indexes) { foreach ($array as $key => $value) { if (!is_numeric($key) || $key < 0) { throw new InvalidArgumentException('array must contain only positive integer keys'); } if ($key >= $fixed_array->count()) { $fixed_array->setSize($key + 1); } $fixed_array[$key] = $value; } } else { $fixed_array->data = array_values($array); } return $fixed_array; }
/** * @param string|int $page * @param string|int $limit * @return Collection */ public function getAllByPages($page = 1, $limit = 20) { $result = new self(); if (!$this->count()) { return $result; } $firstElement = ($page - 1) * $limit; $iterator = $this->getIterator(); $iterator->seek($firstElement); while ($iterator->current() && $result->count() < $limit) { $result->offsetSet($iterator->current()->getId(), $iterator->current()); $iterator->next(); } return $result; }
public static function countMisc() { $payloads = new self(); return $payloads->count(array('pType = ?', 'Miscellaneous')); }
public static function simple_count($table, array $cols = array(), array $conds = array()) { if (any($this->opts['falsify-return-value'])) { return $this->false_return_value; } $helper = new self(array("table" => $table, "conds" => $conds)); return $helper->count(); }
public static function countNew() { $comments = new self(); return $comments->count(array('approved = ?', 0)); }