public function testOccurences() { $str = new Text('let it go'); $this->assertTrue($str->startsWith('let')); $this->assertTrue($str->startsWith(new Text('let'))); $this->assertFalse($str->startsWith('go')); $this->assertFalse($str->startsWith(new Text('go'))); $this->assertTrue($str->endsWith('go')); $this->assertTrue($str->endsWith(new Text('go'))); $this->assertFalse($str->endsWith('let')); $this->assertFalse($str->endsWith(new Text('let'))); $this->assertTrue($str->contains('it')); $this->assertTrue($str->contains(new Text('it'))); $this->assertFalse($str->contains('Hulk')); $this->assertFalse($str->contains(new Text('Hulk'))); $this->assertTrue($str->equals('let it go')); $this->assertTrue($str->equals(new Text('let it go'))); $this->assertFalse($str->equals('Let It Go')); $this->assertTrue($str->equalsIgnoreCase('Let It Go')); $this->assertTrue($str->equalsIgnoreCase(new Text('Let It Go'))); $this->assertFalse($str->isEmpty()); }
/** * Returns whether this path is empty * * @return boolean */ public function isEmpty() { return $this->pathname->isEmpty(); }
/** * * @param Request $request * @throws AppException * @return ApplicationUri */ public function match($request) { $found = null; $uris = ApplicationUriQuery::create()->joinApplication()->filterByHttphost($request->getHttpHost())->find(); $requestUri = Text::create($request->getRequestUri())->trimRight('/'); foreach ($uris as $uri) { $basepath = new Text($uri->getBasepath()); // either request uri and uri basepath are both empty // or request uri starts with basepath if ($basepath->isEmpty() && $uri->getHttphost() == $request->getHttpHost() || $requestUri->startsWith($basepath)) { // assign when it's the first found if ($found === null) { $found = $uri; } else { if ($basepath->count('/') > Text::create($found->getBasepath())->count('/')) { $found = $uri; } } } } if ($found === null) { throw new AppException(sprintf('No app found on %s', $request->getUri()), 404); } $this->destination = str_replace($found->getBasepath(), '', $request->getRequestUri()); return $found; }