/** * @see Collection::drop() * * @observable "collection:<type>:drop:invoke"( object $collectible ) * @observable "collection:<type>:drop:except"( Throwable $e ) */ public function drop($collectible) { if (!$collectible instanceof $this->_type) { if (is_callable($collectible)) { foreach ($this->filter($collectible) as $member) { $this->drop($member); } return; } $t = Vars::type($collectible); $m = "\$collectible must be a collectible object or filter callback; [{$t}] provided"; throw new \TypeError($m, E_USER_WARNING); } try { $this->notify("collection:{$this->_type}:drop:invoke", $collectible); $key = array_search($collectible, $this->_collection); if ($key === false) { throw new CollectionException(CollectionException::NOT_IN_COLLECTION); } unset($this->_collection[$key]); } catch (\Throwable $e) { $this->notify("collection:{$this->_type}:drop:except", $e); throw $e; } }
/** * validates a literal offset value based on defined TYPE rules. * * @param string $offset name of offset to validate against * @param mixed $value the value to test * @throws ModelableException if offset does not exist * @return bool true if validation succeeds; false otherwise */ protected function _literalOffsetValid(string $offset, $value) { if (!isset($this->_prop[$offset])) { $context = ['tr' => ['offset' => $offset]]; throw new ModelableException(ModelableException::INVALID_LITERAL, $context); } $type = $this::TYPE[$offset] ?? null; return $value === null || $type === null || gettype($value) === $type || $value instanceof $type || is_scalar($value) && Vars::is_regex($type) && preg_match($type, (string) $value); }
/** * @see Application::log() * * @observable "application:log:invoke"( string $level, string $message, array $context ) * @observable "application:log:except"( Throwable $e ) */ public function log(string $level, string $message, array $context = []) { $this->notify('application:log:invoke', $level, $message, $context); try { if (isset($this->_logger)) { $this->_logger->log($level, $message, $context); return; } $d = Vars::debug($context); error_log("{$level}: {$message}\n{$d}\n"); } catch (\Throwable $e) { $this->notify('application:log:except', $e); throw $e; } }