/** * Remove the given log message handler if it is registered. * * @param LogHandler $handler */ public function removeHandler(LogHandler $handler) { if ($this->handlers->contains($handler)) { $this->handlers->detach($handler); $this->enabled = $this->handlers->count() ? true : false; } }
public function isVisiting($object) { if (!is_object($object)) { return false; } return $this->visitingSet->contains($object); }
public function isVisiting($object) { if (!is_object($object)) { throw new LogicException('Expected object but got ' . gettype($object) . '. Do you have the wrong @Type mapping or could this be a Doctrine many-to-many relation?'); } return $this->visitingSet->contains($object); }
/** * @param AbstractSQLConnection $connection * * @return bool */ public function findConnection(AbstractSQLConnection $connection) { if ($this->storage->contains($connection)) { return true; } return false; }
/** * Removes the given comparison * * @param PropertyComparisonInterface $comparison * @throws Exception\InvalidComparisonException if the given comparison is not in the list * @return $this */ public function removeComparison($comparison) { if (!$this->comparisons->contains($comparison)) { throw new InvalidComparisonException('Can not remove given comparison because it is not in the list', 1409600320); } $this->comparisons->detach($comparison); }
protected function getBlockId(Block $block) { if (!$this->blocks->contains($block)) { $this->blocks[$block] = count($this->blocks) + 1; } return $this->blocks[$block]; }
/** * Removes the specified validator. * * @param \TYPO3\FLOW3\Validation\Validator\ValidatorInterface $validator The validator to remove * @throws \TYPO3\FLOW3\Validation\Exception\NoSuchValidatorException * @api */ public function removeValidator(\TYPO3\FLOW3\Validation\Validator\ValidatorInterface $validator) { if (!$this->validators->contains($validator)) { throw new \TYPO3\FLOW3\Validation\Exception\NoSuchValidatorException('Cannot remove validator because its not in the conjunction.', 1207020177); } $this->validators->detach($validator); }
/** * @return \Nano\Event\Manager * @param \Nano\Event\Handler $handler */ public function attachHandler(\Nano\Event\Handler $handler) { if ($this->handlers->contains($handler)) { return $this; } $this->handlers->attach($handler); return $this; }
/** * @inheritDoc */ public function addListener(ListenerInterface ...$listeners) { foreach ($listeners as $listener) { if (!$this->listeners->contains($listener)) { $this->listeners->attach($listener); } } }
/** * Detach a autoloadiable * * @param \Attw\Autoloader\AutoloadableInterface */ public function detach(AutoloadableInterface $autoloadable) { if (!$this->autoloadables->contains($autoloadable)) { throw new \Exception('The autoload hasn\'t been duplicated'); } $this->autoloadables->detach($autoloadable); spl_autoload_unregister($autoloadable->getCallable()); }
/** * @param FormInterface $child * @return FormInterface */ public function add(FormInterface $child) { if (FALSE === $this->children->contains($child)) { $this->children->attach($child); $child->setParent($this); } return $this; }
/** * {@inheritdoc} */ public function getLocale() { $request = $this->requestStack->getCurrentRequest(); if (!$this->locales->contains($request)) { $this->locales[$request] = $this->chainResolver->resolve(); } return $this->locales[$request]; }
/** * Adds scope to default scopes * * @param IScope $scope */ public function addDefaultScope(IScope $scope) { if (!$this->defaultScopes->contains($scope)) { $this->defaultScopes->attach($scope); } else { throw new \InvalidArgumentException("Scope '{$scope->getId()}' is already registered as default scope."); } }
/** * Runs the close() method of a backend and removes the backend * from the logger. * * @param Backend\BackendInterface $backend The backend to remove * @return void * @throws NoSuchBackendException if the given backend is unknown to this logger * @api */ public function removeBackend(Backend\BackendInterface $backend) { if (!$this->backends->contains($backend)) { throw new NoSuchBackendException('Backend is unknown to this logger.', 1229430381); } $backend->close(); $this->backends->detach($backend); }
/** * @param Peer $peer * @return PeerState */ public function fetch(Peer $peer) { if (!$this->storage->contains($peer)) { $state = $this->createState($peer); } else { $state = $this->storage->offsetGet($peer); } return $state; }
/** * Removes a Resource object from this repository * * @param object $object * @return void */ public function remove($object) { // Intercept a second call for the same Resource object because it might cause an endless loop caused by // the ResourceManager's deleteResource() method which also calls this remove() function: if (!$this->removedResources->contains($object)) { $this->removedResources->attach($object); parent::remove($object); } }
/** * @param HandlerInterface $handler * @param array $categories */ public function attach(HandlerInterface $handler, array $categories = array()) { if ($this->handlers->contains($handler)) { $handlerCategories = $this->handlers->offsetGet($handler); $this->handlers->offsetSet($handler, array_merge((array) $handlerCategories, $categories)); } else { $this->handlers->attach($handler, $categories); } }
private function traverseBlock(Block $block, Block $prior = null) { if ($this->seen->contains($block)) { $this->event("skipBlock", [$block, $prior]); // Always return null on a skip event return null; } $this->seen->attach($block); $this->event("enterBlock", [$block, $prior]); $children = $block->children; for ($i = 0; $i < count($children); $i++) { $op = $children[$i]; $this->event("enterOp", [$op, $block]); foreach ($op->getSubBlocks() as $subblock) { $sub = $op->{$subblock}; if (!$sub) { continue; } if (!is_array($sub)) { $sub = [$sub]; } for ($j = 0; $j < count($sub); $j++) { $result = $this->traverseBlock($sub[$j], $block); if ($result === Visitor::REMOVE_BLOCK) { array_splice($sub, $j, 1, []); // Revisit the ith block $j--; } elseif ($result instanceof Block) { $sub[$j] = $result; // Revisit the ith block again $j--; } elseif (!is_null($result)) { throw new \RuntimeException("Unknown return from visitor: " . gettype($result)); } } if (is_array($op->{$subblock})) { $op->{$subblock} = $sub; } else { $op->{$subblock} = array_shift($sub); } } $result = $this->event("leaveOp", [$op, $block]); if ($result === Visitor::REMOVE_OP) { array_splice($children, $i, 1, []); // Revisit the ith node $i--; } elseif ($result instanceof Op) { $children[$i] = $result; // Revisit the ith node again $i--; } elseif (!is_null($result) && $result !== $op) { throw new \RuntimeException("Unknown return from visitor: " . gettype($result)); } } $block->children = $children; return $this->event("leaveBlock", [$block, $prior]); }
/** * @inheritDoc */ public function getQuery(Driver $driver, $link) { if (!$this->pool->contains($link)) { throw new \OutOfBoundsException(sprintf('Undefined %s in the pooling controller.', $driver->info($link))); } if (!$this->waiting->isEmpty()) { return $this->waiting->dequeue(); } $this->idle->enqueue($link); }
/** * @param TransactionInterface $tx * @return BufferInterface */ public function serialize(TransactionInterface $tx) { if ($this->storage->contains($tx)) { return $this->storage[$tx]; } else { $serialized = $this->txSerializer->serialize($tx); $this->storage->attach($tx, $serialized); return $serialized; } }
/** * Extract the data from an object * * @param object $object * * @return array */ private function normalizeObject($object) { if ($this->objectToIndex->contains($object)) { return [$this->classAnnotation => '@' . $this->objectToIndex[$object]]; } $this->objectToIndex->attach($object, $this->objectIndex++); $normalizedObject = [$this->classAnnotation => get_class($object)]; $normalizedObject += array_map([$this, 'normalizeValue'], $this->extractObjectProperties($object)); return $normalizedObject; }
/** * @covers ::get */ public function testSameInstance() { $stringTest = Text::get("Testing string"); $differentString = Text::get("Bla Bla Bla"); $sameString = Text::get("Testing string"); $spl = new SplObjectStorage(); $spl->attach($stringTest); self::assertFalse($spl->contains($differentString)); self::assertTrue($spl->contains($sameString)); }
/** * Unregister an AutoLoadable Object * * @param Next\Loader\AutoLoader\AutoLoadable $autoloader * The AutoLoader Object to be registered * * @return Next\AutoLoader * AutoLoader Instance (Fluent Interface) * * @throws Next\LoaderException * Trying to unregister a non registered AutoLoadable Object */ public function unregisterAutoLoader(AutoLoadable $autoloader) { if (!$this->autoloaders->contains($autoloader)) { require_once 'LoaderException.php'; throw LoaderException::unknown(); } $this->autoloaders->detach($autoloader); spl_autoload_unregister($autoloader->call()); return $this; }
/** * @param BlockInterface $block * @return BufferInterface */ public function serialize(BlockInterface $block) { if ($this->storage->contains($block)) { return $this->storage[$block]; } else { $serialized = $this->blockSerializer->serialize($block); $this->storage->attach($block, $serialized); return $serialized; } }
/** * @param Session $session * @param Message $msg */ public function onMessage(Session $session, Message $msg) { if (!$session->isAuthenticated()) { if ($msg instanceof HelloMessage) { $this->manager->debug("got hello"); // send welcome message if ($this->sessions->contains($session)) { $this->manager->error("Connection tried to rejoin realm when it is already joined to the realm."); $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg)); // TODO should shut down session here } else { $this->sessions->attach($session); $session->setRealm($this); $session->setState(Session::STATE_UP); // this should probably be after authentication if ($this->getAuthenticationManager() !== null) { $this->getAuthenticationManager()->onAuthenticationMessage($this, $session, $msg); } else { $session->setAuthenticated(true); $session->setAuthenticationDetails(AuthenticationDetails::createAnonymous()); // the broker and dealer should give us this information $roles = array("broker" => new \stdClass(), "dealer" => new \stdClass()); $session->sendMessage(new WelcomeMessage($session->getSessionId(), array("roles" => $roles))); } } } else { if ($msg instanceof AuthenticateMessage) { if ($this->getAuthenticationManager() !== null) { $this->getAuthenticationManager()->onAuthenticationMessage($this, $session, $msg); } else { // TODO: should shut down here probably $this->manager->error("Authenticate sent to realm without auth manager."); } } else { $this->manager->error("Unhandled message sent to unauthenticated realm: " . $msg->getMsgCode()); $session->sendMessage(new AbortMessage(new \stdClass(), "wamp.error.not_authorized")); $session->shutdown(); } } } else { $handled = false; /* @var $role AbstractRole */ foreach ($this->roles as $role) { if ($role->handlesMessage($msg)) { $role->onMessage($session, $msg); $handled = true; break; } } if (!$handled) { $this->manager->warning("Unhandled message sent to \"{$this->getRealmName()}\": {$msg->getSerializedMessage()}"); } } }
/** * Visit the $visitable. * * Each node in the graph is visited once. * * @param ezcWorkflowVisitable $visitable * @return bool */ public function visit(ezcWorkflowVisitable $visitable) { if ($visitable instanceof ezcWorkflowNode) { if ($this->visited->contains($visitable)) { return false; } $this->visited->attach($visitable); } $this->doVisit($visitable); return true; }
/** * @param object $object * @return boolean */ protected function isValidatedAlready($object) { if ($this->validatedInstancesContainer === null) { $this->validatedInstancesContainer = new \SplObjectStorage(); } if ($this->validatedInstancesContainer->contains($object)) { return true; } else { $this->validatedInstancesContainer->attach($object); return false; } }
/** * {@inheritdoc} */ public function cancel(ImmediateInterface $immediate) { if ($this->immediates->contains($immediate)) { $this->immediates->detach($immediate); foreach ($this->queue as $key => $event) { if ($event === $immediate) { unset($this->queue[$key]); break; } } } }
private function updateDefinitionArguments(Definition $definition) { if ($this->visitedDefinitions->contains($definition)) { return; } $this->visitedDefinitions->attach($definition); $definition->setProperties($this->updateArguments($definition->getProperties())); $definition->setArguments($this->updateArguments($definition->getArguments())); $methodsCalls = array(); foreach ($definition->getMethodCalls() as $index => $call) { $methodsCalls[$index] = array($call[0], $this->updateArguments($call[1])); } $definition->setMethodCalls($methodsCalls); }
/** * @param mixed $key * * @return Option */ protected function getMapKey($key) { $key = $this->getObjectKey($key); if ($this->map->contains($key)) { return new Some($key); } // Search by equalable... foreach ($this->map as $mapKey) { if (ComparisonHelper::isEquals($key, $mapKey)) { return new Some($mapKey); } } return new None(); }