Пример #1
0
 /**
  * @param string|Text $key
  * @return string
  */
 private function extractKey($key)
 {
     if ($key instanceof Text) {
         return $key->toString();
     }
     return $key;
 }
Пример #2
0
 private function parseExtensions(Map $data)
 {
     $this->extensions = new Map();
     foreach ($data as $k => $v) {
         $key = new Text($k);
         if ($key->startsWith('x-')) {
             $this->extensions->set($key->substring(2), $v);
         }
     }
 }
Пример #3
0
 /**
  *
  * @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;
 }
Пример #4
0
 /**
  * @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));
     }
 }
Пример #5
0
 protected function preSave(Object $object)
 {
     // set slug
     if (Text::create($object->getSlug())->isEmpty()) {
         $slugifier = new Slugify();
         $object->setSlug($slugifier->slugify($object->getTitle()));
     }
 }
Пример #6
0
 /**
  * @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();
 }
Пример #7
0
 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);
 }
Пример #8
0
 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);
 }
Пример #9
0
 /**
  * Checks whether both paths point to the same location
  * 
  * @param Path|string $anotherPath
  * @return boolean true if the do, false if they don't
  */
 public function equals($anotherPath)
 {
     $anotherPath = $anotherPath instanceof Path ? $anotherPath : new Path($anotherPath);
     // do something else, when path's are urls
     $regexp = '/^[a-zA-Z]+:\\/\\//';
     $thisUrl = $this->pathname->match($regexp);
     $anotherUrl = $anotherPath->getPathname()->match($regexp);
     if ($thisUrl ^ $anotherUrl) {
         return false;
     } else {
         if ($thisUrl && $anotherUrl) {
             return $this->pathname->equals($anotherPath->getPathname());
         }
     }
     return realpath($this->pathname->toString()) == realpath($anotherPath->toString());
 }
Пример #10
0
 /**
  * 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);
 }
Пример #11
0
 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()));
     }
 }
Пример #12
0
 /**
  * {@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;
 }
Пример #13
0
 /**
  * @param mixed $query
  * @param mixed $filter
  * @return void
  */
 protected function applyFilter($query, $filter)
 {
     if (is_array($filter)) {
         // filter by fields
         if (isset($filter['fields'])) {
             foreach ($filter['fields'] as $column => $value) {
                 $pos = strpos($column, '.');
                 if ($pos !== false) {
                     $rel = NameUtils::toStudlyCase(substr($column, 0, $pos));
                     $col = substr($column, $pos + 1);
                     $method = 'use' . $rel . 'Query';
                     if (method_exists($query, $method)) {
                         $sub = $query->{$method}();
                         $this->applyFilter($sub, ['fields' => [$col => $value]]);
                         $sub->endUse();
                     }
                 } else {
                     $method = 'filterBy' . NameUtils::toStudlyCase($column);
                     if (method_exists($query, $method)) {
                         $query->{$method}($value);
                     }
                 }
             }
         }
         // filter by features
         if (isset($filter['features'])) {
             $features = new Text($filter['features']);
             if ($features->contains('random')) {
                 $query->addAscendingOrderByColumn('RAND()');
             }
         }
     }
     if (method_exists($this, 'filter')) {
         $this->filter($query, $filter);
     }
 }
Пример #14
0
 public function testIndexSearch()
 {
     $str = new Text('let it go');
     $this->assertEquals(4, $str->indexOf('it'));
     $this->assertEquals(4, $str->indexOf(new Text('it')));
 }
Пример #15
0
 /**
  * @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;
 }
Пример #16
0
 /**
  * Sets the full name (vendor/name) of the package
  *
  * @param string $name
  * @return $this
  */
 public function setFullName($name)
 {
     $fullName = new Text($name);
     $this->fullName = $name;
     $this->name = $fullName->substring($fullName->indexOf('/') + 1)->toString();
     $this->vendor = $fullName->substring(0, $fullName->indexOf('/'))->toString();
     return $this;
 }