本文整理汇总了PHP中Queue::enqueue方法的典型用法代码示例。如果您正苦于以下问题:PHP Queue::enqueue方法的具体用法?PHP Queue::enqueue怎么用?PHP Queue::enqueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue::enqueue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getQueue
/**
* @return Queue
*/
public function getQueue()
{
$aParts = str_split($this->_expression);
$oQueue = new Queue();
foreach ($aParts as $sPart) {
if (Token::isTokenNumericOrDecimalPoint($sPart)) {
if ($oQueue->hasItems()) {
if ($oQueue->isLastTokenNumeric()) {
$oQueue->appendToLastToken(new Token($sPart));
}
}
$oQueue->enqueue(new Token($sPart));
} elseif (Token::isTokenParenthesis($sPart)) {
$oQueue->enqueue(new Parenthesis($sPart));
} else {
$oQueue->enqueue(new Operator($sPart));
}
}
return $oQueue;
}
示例2: preWork
public static function preWork(&$controllerContext, &$viewContext)
{
$controllerContext->cache->setPrefix($controllerContext->userName);
if (BanHelper::getUserBanState($controllerContext->userName) == BanHelper::USER_BAN_TOTAL) {
$controllerContext->cache->bypass(true);
$viewContext->userName = $controllerContext->userName;
$viewContext->viewName = 'error-user-blocked';
$viewContext->meta->title = 'User blocked — ' . Config::$title;
return;
}
$module = $controllerContext->module;
HttpHeadersHelper::setCurrentHeader('Content-Type', $module::getContentType());
$viewContext->media = $controllerContext->media;
$viewContext->module = $controllerContext->module;
$viewContext->meta->noIndex = true;
$viewContext->contentType = $module::getContentType();
if ($viewContext->contentType != 'text/html') {
$viewContext->layoutName = 'layout-raw';
}
Database::selectUser($controllerContext->userName);
$user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$controllerContext->userName]);
if (empty($user)) {
if (!isset($_GET['referral']) || $_GET['referral'] !== 'search') {
$controllerContext->cache->bypass(true);
$viewContext->userName = $controllerContext->userName;
$viewContext->viewName = 'error-user-not-found';
$viewContext->meta->title = 'User not found — ' . Config::$title;
return;
}
$queue = new Queue(Config::$userQueuePath);
$queueItem = new QueueItem(strtolower($controllerContext->userName));
$queue->enqueue($queueItem);
$viewContext->queuePosition = $queue->seek($queueItem);
$controllerContext->cache->bypass(true);
//try to load cache, if it exists
$url = $controllerContext->url;
if ($controllerContext->cache->exists($url)) {
$controllerContext->cache->load($url);
flush();
$viewContext->layoutName = null;
$viewContext->viewName = null;
return;
}
$viewContext->userName = $controllerContext->userName;
$viewContext->viewName = 'error-user-enqueued';
$viewContext->meta->title = 'User enqueued — ' . Config::$title;
return;
}
$viewContext->user = $user;
$viewContext->meta->styles[] = '/media/css/menu.css';
$viewContext->updateWait = Config::$userQueueMinWait;
$module = $controllerContext->module;
$module::preWork($controllerContext, $viewContext);
}
示例3: testStructure
public static function testStructure()
{
$queue = new Queue();
if ($queue->getCount() !== 0) {
self::printError("problem creating a new queue - count not 0");
}
// test enqueue
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$queue->enqueue(4);
$queue->enqueue(5);
if ($queue->getCount() !== 5) {
self::printError("problem enqueueing. count not 5");
}
// display... for now
$queue->display();
// test dequeue
$data = $queue->dequeue();
if ($data !== 1) {
self::printError("problem dequeueing. value not 1");
}
if ($queue->getCount() !== 4) {
self::printError("problem dequeueing. count not 4");
}
$data = $queue->dequeue();
$data = $queue->dequeue();
$data = $queue->dequeue();
$data = $queue->dequeue();
if ($data !== 5) {
self::printError("problem dequeueing. value not 5");
}
if ($queue->getCount() !== 0) {
self::printError("problem dequeueing. count not 0");
}
// display... for now
$queue->display();
}
示例4: actionView
public function actionView()
{
$services = Service::model()->findAllByAttributes(['status' => 0]);
$task = [];
$url = $this->app->createUrl('api/view');
foreach ($services as $service) {
$task[] = Queue::createTask($url, $service->uid);
}
if (Queue::enqueue($task, true)) {
echo "Success";
} else {
echo "Failed";
}
}
示例5: work
public static function work(&$controllerContext, &$viewContext)
{
$queue = new Queue(Config::$userQueuePath);
$queueItem = new QueueItem(strtolower($controllerContext->userName));
$user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$controllerContext->userName]);
$profileAge = time() - strtotime($user->processed);
$banned = BanHelper::getUserBanState($controllerContext->userName) != BanHelper::USER_BAN_NONE;
if ($profileAge > Config::$userQueueMinWait and !$banned && Config::$enqueueEnabled) {
$queue->enqueue($queueItem);
}
$j['user'] = $controllerContext->userName;
$j['pos'] = $queue->seek($queueItem);
$viewContext->layoutName = 'layout-json';
$viewContext->json = $j;
}
示例6: testCanCreateStaticProxies
public function testCanCreateStaticProxies()
{
// Instantiate XStatic and use setContainer
$proxyManager = new ProxyManager($this->getMock('Interop\\Container\\ContainerInterface'));
$proxyManager->setContainer(new Fixture\Container(array('queue' => new \SplQueue())));
// Register a proxy and enable them
$proxyManager->addProxy('Queue', 'XStatic\\Test\\Fixture\\QueueProxy');
$enabled = $proxyManager->enable();
$this->assertTrue($enabled);
// Enable again, which should be a no-op
$proxyManager->enable();
// Test to see if the alias was loaded and works as a static proxy
\Queue::enqueue('foo');
$queue = \Queue::getInstance();
$this->assertInstanceOf('SplQueue', $queue);
$this->assertEquals('foo', $queue->dequeue());
}
示例7: run
public function run()
{
$uid = $this->request->getQuery('id', 0);
$service = Service::model()->findByPk($uid);
if (!empty($service)) {
if (in_array($service->status, [1, 2])) {
// 不可用状态
$task = Queue::createTask($this->app->createUrl('api/open'), $uid);
} else {
$task = Queue::createTask($this->app->createUrl('api/close'), $uid);
}
if (Queue::enqueue($task)) {
$this->response(200, ':) success');
} else {
$this->response(200, ':( failure');
}
} else {
$this->response(404, 'Not Found');
}
}
示例8: find_files
function find_files($path, Queue &$result)
{
$files = SysDirectory::getFiles($path);
$iterator =& $files->getIterator();
while ($iterator->hasNext()) {
$entry =& $iterator->next();
if ('php' == $entry->getExtension()) {
if (!$result->contains($entry)) {
$result->enqueue($entry);
}
}
}
$dirs = SysDirectory::getDirectories($path);
if ($dirs->size() > 0) {
$iterator =& $dirs->getIterator();
while ($iterator->hasNext()) {
$entry =& $iterator->next();
/*
if ( $entry->getName() != '.' && $entry->getName() != '..' )
find_files( (string)$entry, $result );
*/
}
}
}
示例9: enqueue
*/
public function enqueue($el)
{
array_push($this->_queue, $el);
}
/**
* Dequeue the front element from the queue.
*
* @return mixed $element.
*/
public function dequeue()
{
if ($this->front() !== null) {
return array_shift($this->_queue);
}
return null;
}
}
// Example usage:
$queue = new Queue();
$queue->enqueue("Element");
$queue->enqueue(23);
$queue->enqueue(array(3, 4, 6));
while (!$queue->is_empty()) {
echo "The front element is now : \n";
var_dump($queue->front());
echo "\n";
$queue->dequeue();
}
// Outputs NULL
var_dump($queue->front());
示例10: enqueue
protected $dataStore = [];
public function enqueue($element)
{
array_push($this->dataStore, $element);
parent::enqueue($element);
}
public function dequeue()
{
array_shift($this->dataStore);
return parent::dequeue();
}
public function toString()
{
$retStr = "";
$cnt = count($this->dataStore);
for ($i = 0; $i < $cnt; ++$i) {
$retStr .= $this->dataStore[$i] . "\n";
}
return $retStr . "\n";
}
}
$users = ["Вася", "Петя", "Федя", "Саша", "Зина", "Маша"];
$q = new Queue();
foreach ($users as $user) {
$q->enqueue($user);
}
echo "Кто в очереди:\n" . $q->toString();
echo $q->dequeue() . " вышел\n";
echo "Кто в очереди:\n" . $q->toString();
echo "Кто первый: " . $q->bottom() . "\n";
echo "Кто последний: " . $q->top() . "\n";
示例11: isFull
{
if ($this->front === null) {
return true;
} else {
return false;
}
}
public function isFull()
{
}
}
$q = new Queue(5);
// instantiates the Queue class with a maxSize attribute of 5
$q->isEmpty();
// returns true
$q->enqueue(100);
// Queue: 100
$q->rear();
// returns 100
$q->front();
// returns 100
$q->enqueue(20);
// Queue: 100, 20
$q->enqueue(2);
// Queue: 100, 20, 2
$q->dequeue();
// Queue: 20, 2
$q->enqueue(500);
// Queue: 20, 2, 500
$q->enqueue(12);
// Queue: 20, 2, 500, 12
示例12: formCluster
/**
* Forms the clusters by removing maximum weighted edges.
* performs breadth-first search to cluster the recipes.
*
* @param int $k queue size
* @param int $size number of recipes.
* @return array $cluster clusters of recipes.
*/
function formCluster($k, $size)
{
$this->cluster_heap->top();
$nodeQueue = new Queue($k);
$cluster_count = $size * CLUSTER_RATIO;
$cluster = array();
/*
Idea remove $cluster_count many weightiest edges from tree
to get a forest. As do this add to queue end points of
removed edges.
*/
for ($j = 0; $j < $cluster_count - 1; $j++) {
$max_edge = $this->cluster_heap->extract();
$cluster1_start = $max_edge->getStartVertex()->getLabel();
$cluster2_start = $max_edge->getEndVertex()->getLabel();
$this->adjMatrix[$cluster1_start][$cluster2_start] = -1;
$this->adjMatrix[$cluster2_start][$cluster1_start] = -1;
$nodeQueue->enqueue($cluster1_start);
$nodeQueue->enqueue($cluster2_start);
}
$queue = new Queue($k);
$i = 0;
// Now use Queue above to make clusters (trees in resulting forest)
while (!$nodeQueue->isEmpty()) {
$node = $nodeQueue->dequeue();
if ($this->vertices[$node]->isVisited() == false) {
$this->vertices[$node]->visited();
$cluster[$i][] = $this->vertices[$node]->getLabel();
$queue->enqueue($this->vertices[$node]->getLabel());
while (!$queue->isEmpty()) {
$node = $queue->dequeue();
while (($nextnode = $this->getNextVertex($node)) != -1) {
$this->vertices[$nextnode]->visited();
$cluster[$i][] = $this->vertices[$nextnode]->getLabel();
$queue->enqueue($this->vertices[$nextnode]->getLabel());
}
}
}
$i++;
}
return $cluster;
}
示例13: apiReset
public static function apiReset($uid)
{
$url = Yii::app()->createurl('api/reset');
$task = Queue::createTask($url, $uid, 'api/close');
Queue::enqueue($task);
}
示例14: _moveTopOperatorToOutput
/**
* Move top operator to output queue
*/
protected function _moveTopOperatorToOutput()
{
$oTopOperator = $this->_operator_stack->pop();
$this->_output_queue->enqueue($oTopOperator);
}
示例15: __toString
/**
* Converts queue collection to string output.
*/
public function __toString()
{
if ($this->isEmpty()) {
$itemsString = 'Queue is empty.';
} else {
$itemsString = implode(', ', $this->items);
}
$itemsString .= PHP_EOL;
return $itemsString;
}
}
$queue = new Queue();
$queue->enqueue('A');
echo (string) $queue;
// A
$queue->dequeue();
echo (string) $queue;
// Queue is empty.
$queue->dequeue();
echo (string) $queue;
// Queue is empty.
$queue->enqueue('B');
echo (string) $queue;
// B
$queue->enqueue('C');
echo (string) $queue;
// B, C
$queue->enqueue('D');