public function testToText() { $str = new Text('bla'); $this->assertEquals('bla', '' . $str); $str = Text::create('bla'); $this->assertEquals('bla', '' . $str); }
/** * @param Group $model */ protected function preCreate(Group $model) { if (Text::create($model->getSlug())->isEmpty()) { $title = $model->getTitle(); $slugifier = new Slugify(); $model->setSlug($slugifier->slugify($title)); } }
protected function preSave(Object $object) { // set slug if (Text::create($object->getSlug())->isEmpty()) { $slugifier = new Slugify(); $object->setSlug($slugifier->slugify($object->getTitle())); } }
/** * @param Skill $skill * @param mixed $data */ protected function preSave(Skill $skill) { // set slug if (Text::create($skill->getSlug())->isEmpty()) { $name = str_replace('°', '', $skill->getName()); $slugifier = new Slugify(); $skill->setSlug($slugifier->slugify($name)); } $this->isNew = $skill->isNew(); }
private function parse($contents) { $data = CollectionUtils::toMap($contents); // paths $this->paths = new Map(); foreach ($data as $p => $path) { if (!Text::create($p)->startsWith('x-')) { $this->paths->set($p, new Path($p, $path)); } } // extensions $this->parseExtensions($data); }
private function parse($contents) { $data = CollectionUtils::toMap($contents); // responses $this->responses = new Map(); foreach ($data as $r => $response) { if (!Text::create($r)->startsWith('x-')) { $this->responses->set($r, new Response($r, $response)); } } // extensions $this->parseExtensions($data); }
/** * Automatically generated run method * * @param Request $request * @return Response */ public function run(Request $request) { $routes = $this->generateRoutes(); $context = new RequestContext($this->getBaseUrl()); $matcher = new UrlMatcher($routes, $context); $match = $matcher->match($this->getDestination()); $route = $match['_route']; unset($match['_route']); if (Text::create($route)->startsWith('sport-')) { $route = 'sport'; } $action = $this->getModule()->loadAction($route, 'html'); $action->setParams($match); if ($route == 'sport') { $action->setBaseUrl($this->getBaseUrl()); } $kernel = $this->getServiceContainer()->getKernel(); return $kernel->handle($action, $request); }
protected function preSave(Sport $sport) { $slugifier = new Slugify(); // set slug if (Text::create($sport->getSlug())->isEmpty()) { $sport->setSlug($slugifier->slugify($sport->getTitle())); } // set object slug if (Text::create($sport->getObjectSlug())->isEmpty() && !Text::create($sport->getObjectLabel())->isEmpty()) { $sport->setObjectSlug($slugifier->slugify($sport->getObjectLabel())); } // set skill slug if (Text::create($sport->getSkillSlug())->isEmpty()) { $sport->setSkillSlug($slugifier->slugify($sport->getSkillLabel())); } // set group slug if (Text::create($sport->getGroupSlug())->isEmpty()) { $sport->setGroupSlug($slugifier->slugify($sport->getGroupLabel())); } }
/** * {@inheritDoc} */ public function generate(GenerateableInterface $model) { $content = "<?php\n"; $comment = $this->config->getHeaderComment(); if ($comment !== null && !$comment->isEmpty()) { $content .= str_replace('/**', '/*', $comment->toString()) . "\n"; } $docblock = $this->config->getHeaderDocblock(); if ($docblock !== null && !$docblock->isEmpty()) { $content .= $docblock->toString() . "\n"; } if ($this->config->getDeclareStrictTypes()) { $content .= "declare(strict_types=1);\n\n"; } $content .= parent::generate($model); if ($this->config->getBlankLineAtEnd() && !Text::create($content)->endsWith("\n")) { $content .= "\n"; } return $content; }
/** * @param string $name * @return Startgroup */ private function getStartgroup($name) { $name = $this->translate($name); // some special cases $competition = null; if ($name == 'Junior Expert (male)' || $name == 'Expert (male)') { $competition = $this->competitions->get('Individual Freestyle (male)'); $startgroupName = str_replace(' (male)', '', $name); } else { if ($name == 'Junior Expert (female)' || $name == 'Expert (female)') { $competition = $this->competitions->get('Individual Freestyle (female)'); $startgroupName = str_replace(' (female)', '', $name); } } if ($competition === null) { $words = new Set(); foreach (array_values($this->translations) as $names) { $words->addAll(Text::create($names)->split(' ')); } $startgroupName = trim(str_replace($words->toArray(), '', $name)); $words = Text::create($startgroupName)->split(' '); $competitionName = preg_replace('/\\s\\s+/', ' ', trim(str_replace($words->toArray(), '', $name))); if (!$this->competitions->has($competitionName)) { throw new \Exception('Cannot find competition for ' . $competitionName); } $competition = $this->competitions->get($competitionName); } $startgroup = new Startgroup(); $startgroup->setName($startgroupName); $startgroup->setSlug(NameUtils::dasherize(strtolower($startgroupName))); $startgroup->setCompetition($competition); return $startgroup; }
/** * * @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; }