本文整理匯總了PHP中GrumPHP\Configuration\GrumPHP::getTaskMetadata方法的典型用法代碼示例。如果您正苦於以下問題:PHP GrumPHP::getTaskMetadata方法的具體用法?PHP GrumPHP::getTaskMetadata怎麽用?PHP GrumPHP::getTaskMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GrumPHP\Configuration\GrumPHP
的用法示例。
在下文中一共展示了GrumPHP::getTaskMetadata方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1:
function it_should_sort_on_priority(TaskInterface $task1, TaskInterface $task2, TaskInterface $task3, GrumPHP $grumPHP)
{
$this->beConstructedWith(array($task1, $task2, $task3));
$task1->getName()->willReturn('task1');
$task2->getName()->willReturn('task2');
$task3->getName()->willReturn('task3');
$grumPHP->getTaskMetadata('task1')->willReturn(array('priority' => 100));
$grumPHP->getTaskMetadata('task2')->willReturn(array('priority' => 200));
$grumPHP->getTaskMetadata('task3')->willReturn(array('priority' => 100));
$result = $this->sortByPriority($grumPHP);
$result->shouldBeAnInstanceOf('GrumPHP\\Collection\\TasksCollection');
$result->count()->shouldBe(3);
$tasks = $result->toArray();
$tasks[0]->shouldBe($task2);
$tasks[1]->shouldBe($task1);
$tasks[2]->shouldBe($task3);
}
示例2: sortByPriority
/**
* This method sorts the tasks by highest priority first.
*
* @param GrumPHP $grumPHP
*
* @return TasksCollection
*/
public function sortByPriority(GrumPHP $grumPHP)
{
$priorityQueue = new SplPriorityQueue();
$stableSortIndex = PHP_INT_MAX;
foreach ($this->getIterator() as $task) {
$metadata = $grumPHP->getTaskMetadata($task->getName());
$priorityQueue->insert($task, array($metadata['priority'], $stableSortIndex--));
}
return new TasksCollection(array_values(iterator_to_array($priorityQueue)));
}