/** * {@inheritdoc} */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) { if ($this->enabled) { $ip = IP::fromStringIP($request->getClientIp()); $valid = F\some($this->whiteList, function ($range) use($ip) { return $ip->isInRange($range); }); if (!$valid) { return new Response('Forbidden', 403); } } return $this->app->handle($request, $type, $catch); }
/** * Check if all types are the same, in which case just return that type. * Otherwise, create the UnionType and return. * Also automatically flatten all nested UnionTypes. * * @param Type $type Require at least one type * @param Type|Type[] ...$types * * @return UnionType|Type */ public static function createIfNotDuplicate(Type $type, Type ...$types) { $types = array_merge([$type], $types); // Flatten nested UnionTypes $types = Type::flatten($types); if (array_any($types, function (Type $type, $key, array $collection) { return $type instanceof UnionType; })) { throw new \LogicException("UnionType::flatten() failed to flatten nested UnionTypes."); } $types = Type::unique($types); if (count($types) <= 1) { return first($types); } return new UnionType(array_shift($types), $types); }
public function juggle(Type $type) { /* * This is a predicate to determine whether the CURRENT type (the child class) * can be juggled into the Type $type. */ $predicate = function (Type $element) { return array_any($this->getAllowedJuggleTypes(), function (Type $value, $index, $collection) use($element) { return (bool) Type::intersect($element, $value); }); }; $x = array_filter($type->getTypes(), $predicate); if (!$x) { return null; } if (count($x) === 1) { return first($x); } return UnionType::createIfNotDuplicate(array_shift($x), ...$x); }
public function testExceptionThrownInCollection() { $this->setExpectedException('DomainException', 'Callback exception'); some($this->goodIterator, [$this, 'exception']); }