/** * Runs through all the routes and runs them * @author Tim Perry */ public function route() { $this->routes->rewind(); while ($this->routes->valid()) { $route = $this->routes->current(); if ($route->run()) { return; } $this->routes->next(); } throw new \RuntimeException("FlexPress router: No route found - please make sure you have setup routes."); }
/** * Runs through all the callable functions provided, if all are met call the given callable * @author Tim Perry */ public function run() { if (!isset($this->conditions) || !isset($this->callable)) { $message = "You have called the run function but have not provided both a array of conditions"; $message .= " and a callable function, which will be called if all the given conditions are met."; throw new \RuntimeException($message); } $this->conditions->rewind(); while ($this->conditions->valid()) { $condition = $this->conditions->current(); if (!call_user_func($condition)) { return false; } $this->conditions->next(); } call_user_func($this->callable, $this->request); return true; }
/** * 调用 middleware * * @return mixed */ public function call() { $this->queue->rewind(); while ($this->queue->valid()) { if ($this->getPropagation()) { break; } $callbale = $this->queue->current(); $response = call_user_func_array($callbale, func_get_args()); if ($response === false) { break; } elseif (!empty($response)) { $this->response = $response; } $this->queue->next(); } return $this->response; }
/** * Return breadcrumb string **/ function StringifyBreadcrumbs() { $output = "<ul class=\"breadcrumb\" id=\"breadcrumb\">"; if (0 != $this->GetConfigValue('enable_breadcrumbs') && isset($_SESSION['user']) && isset($_SESSION['breadcrumbs'])) { $delimiter = $this->GetConfigValue('breadcrumb_node_delimiter'); $q = new SplQueue(); $q->unserialize($_SESSION['breadcrumbs']); $q->rewind(); $output .= "<li>"; $output .= "<a href=\"" . $this->Href('', $q->current()) . "\">" . $q->current() . "</a>"; $q->next(); while ($q->valid()) { $output .= " {$delimiter} "; $output .= "</li><li>"; $output .= "<a href=\"" . $this->Href('', $q->current()) . "\">" . $q->current() . "</a>"; $q->next(); } $output .= "</li></ul>"; } return $output; }
$qoperatingsystems->push(array('Windows 7', 'desktop', 'NT', 56.11)); $qoperatingsystems->push(array('Windows XP', 'desktop', 'NT', 10.59)); $qoperatingsystems->push(array('Windows 8', 'desktop', 'NT', 2.88)); $qoperatingsystems->push(array('Windows 8.1', 'desktop', 'NT', 11.15)); $qoperatingsystems->push(array('Windows 10', 'desktop', 'NT', 9)); $qoperatingsystems->push(array('Windows Vista', 'desktop', 'NT', 0)); $qoperatingsystems->push(array('Mac OS X 11', 'desktop', 'Unix', 2.66)); $qoperatingsystems->push(array('Mac OS X 10', 'desktop', 'Unix', 2.45)); $qoperatingsystems->push(array('Linux Mint', 'desktop', 'Linux', 0)); $qoperatingsystems->push(array('Linux Debian', 'desktop', 'Linux', 0)); $qoperatingsystems->push(array('Android', 'mobile', 'Linux', 48.12)); $qoperatingsystems->push(array('iOS', 'mobile', 'Unix', 34.71)); echo "\nSPL QUEUE ARRAY FOR LOOP: FIFO\n"; $qoperatingsystems->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO); for ($qoperatingsystems->rewind(); $qoperatingsystems->valid(); $qoperatingsystems->next()) { echo $qoperatingsystems->current()[0] . "\n"; echo $qoperatingsystems->current()[1] . "\n"; echo $qoperatingsystems->current()[2] . "\n"; echo $qoperatingsystems->current()[3] . "\n"; } /* ------------------BASIC OPERATIONS------------------ */ // SORT // BY LANGUAGE RANKING usort($nlanguages, function ($a, $b) { return $b[2] - $a[2]; }); // FILTER // BY DATABASE SIZE function serveronly($var) { if ($var[2] == 'Server') {
/** * Determines if we have a valid buffer for optimising. * * Has to be G1s all round with no Z movements, and either all extrusions or all movements. * * The extrusions also have to be the same mm^3/mm along the path. * * They also have to describe a circle * @param SplQueue $buffer The buffer * @return Boolean Whether the buffer is valid */ function bufferValid($buffer) { global $debug; global $pos_error; for ($buffer->rewind(); $buffer->valid(); $buffer->next()) { if (substr($buffer->current(), 0, 2) !== "G1") { $buffer->rewind(); return false; } else { if (strpos($buffer->current(), "Z") !== FALSE) { $buffer->rewind(); return false; } } } $lines = getLines($buffer); $allE = false; $allF = false; if (!is_null($lines[0]['E'])) { $allE = true; } if (!is_null($lines[0]['F'])) { $allF = true; } foreach ($lines as $num => $line) { $allE = $allE && is_null($line['F']) && !is_null($line['E']); $allF = $allF && is_null($line['E']) && !is_null($line['F']); } if (!($allE || $allF)) { $buffer->rewind(); return false; } if ($allE) { $extrusions = getExtrusionLengths($lines); $eerror = calculateExtrusionError($extrusions); if (calculateExtrusionError($extrusions) === false) { $buffer->rewind(); return false; } } $lines->rewind(); $circle = getCircle($lines); if ($circle === false) { $buffer->rewind(); return false; } if (max($circle['errors']) > $pos_error) { return false; } $buffer->rewind(); return $circle; }
/** * Determine if a binary tree rooted at $node satisfies the binary search tree property (every child in the nodes * subtree is less than or equal to the node and every child in the nodes right tree is greater than or equal to the * node). This works by traversing through each node using BFS and adding an entry to the queue with the current node * and the range constraint that the node value must satisfy. Starting at the root node, the root node is added to the * queue along with the range constraint [-infinity, infinity]. Then the left child node of the root is added to the * queue with the constraint [-infinity, root node key]. Then the right child node of the root is added to the queue * with the constraint [root node key, infinity]. The root node is then popped from the queue. Each child node key * will then be checked against the stored constraints, their children added and then they will be popped. If any * constraint is not met, the binary tree does not satisfy the BST property. * * i.e. * If the input tree is: * 8 * / \ * 3 7 * / \ \ * 1 6 14 * * $queue = [ * $node (with key 8), -infinity, infinity * ] * Is 8 < -infinity or > infinity? No * $queue = [ * $node (with key 3), -infinity, 8 * $node (with key 7), 8, infinity * ] * * Is 3 < -infinity or > 8? No * Is 7 < 8 or > infinity? Yes * * This tree does not satisfy the BST property * * @param Node|null $node * @return bool */ function testForBstPropertyUsingQueue(Node $node = null) { if (empty($node)) { return true; } $queue = new \SplQueue(); $queue->enqueue([$node, -9.223372036854776E+18, PHP_INT_MAX]); while (!$queue->isEmpty()) { if (!empty($queue->current())) { if ($queue->current()[0]->key < $queue->current()[1] || $queue->current()[1]->key > $queue->current()[2]) { return false; } $queue->enqueue([$node->left, $queue->current()[1], $queue->current()[0]->key]); $queue->enqueue([$node->right, $queue->current()[0]->key], $queue->current()[2]); } $queue->pop(); } return true; }
/** * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return string|integer|boolean Can return any type. */ public function current() { return $this->queue->current(); }