Ejemplo n.º 1
0
 /**
  * Set paths in normalized form
  *
  * @param array $paths
  */
 protected function setPaths(array $paths)
 {
     $this->paths = [];
     foreach ($paths as $path) {
         $this->paths[] = Strings::normalizePath($path);
     }
 }
Ejemplo n.º 2
0
 /**
  * Get method name of action if exists and it is accessible
  *
  * @param string $action
  * @return string
  */
 protected function getActionMethodName(string $action) : string
 {
     $method = Strings::methodName($action) . 'Action';
     // Checking method
     if (method_exists($this, $method)) {
         $reflection = new \ReflectionMethod($this, $method);
         // Only public methods
         if ($reflection->isPublic() && $reflection->getName() === $method) {
             return $method;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Get controller instance for path
  *
  * @param string $name
  * @throws RuntimeException
  * @return CargoHandlerInterface|NULL
  */
 protected function pathToController(string $name)
 {
     if (preg_match(static::CLASS_NAME_PATTERN, $name)) {
         $fullName = $this->classPrefix . Strings::className($name);
         // Test class
         if ($this->container->has($fullName)) {
             $instance = $this->container->get($fullName);
             if ($instance instanceof CargoHandlerInterface) {
                 return $instance;
             }
             throw new RuntimeException(sprintf(static::EXCEPTION_INVALID_CLASS, get_class($instance)));
         }
     }
     return null;
 }
Ejemplo n.º 4
0
 /**
  * Generate session id
  *
  * @return string
  */
 protected function generateId() : string
 {
     return sha1(Strings::generateRandom(24) . uniqid('', true) . microtime(true));
 }
Ejemplo n.º 5
0
 protected function renderItems() : string
 {
     $source = '';
     $itemR = $this->itemSize * $this->ratio;
     foreach ($this->items as $item) {
         $px = $item->px;
         $py = $item->py;
         $source .= '<g class="' . $this->itemCssClass($item) . "\">\n" . $this->tag('ellipse', ['cx' => $px, 'cy' => $py, 'rx' => $itemR, 'ry' => $itemR * $this->ellipseRatio]) . $this->itemText($px, $py, Strings::textFromCamelCase($item->getShortName())) . "</g>\n";
     }
     return $source;
 }
Ejemplo n.º 6
0
Archivo: Item.php Proyecto: fixin/fixin
 /**
  * @return Item
  */
 public function getImplementationOf()
 {
     $name = $this->getName();
     foreach ($this->getInterfaces() as $interface) {
         $interfaceName = $interface->name;
         if (Strings::endsWith($interfaceName, 'Interface') && $name === mb_substr($interfaceName, 0, -9)) {
             return $this->processor->getItem($interfaceName);
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 /**
  * Add route segments
  *
  * @param array $segments
  * @param array $path
  * @param string $uri
  * @param array $parameters
  * @param int $level
  */
 protected function addRouteSegments(array $segments, array $path, string $uri, array $parameters, int $level)
 {
     // End
     if (empty($segments)) {
         array_unshift($path, $level);
         return $this->addRouteItem($path, $uri, $parameters);
     }
     $segment = array_shift($segments);
     // Parameter
     if (Strings::surroundedBy($segment, '{', '}')) {
         return $this->addRouteParameterSegment(substr($segment, 1, -1), $segments, $path, $uri, $parameters, $level);
     }
     // Normal segment
     $path[] = $segment;
     $this->addRouteSegments($segments, $path, $uri . '/' . str_replace('%', '%%', $segment), $parameters, $level + 1);
 }