示例#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);
     }
 }
示例#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;
 }
示例#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;
 }
示例#4
0
 /**
  * Generate session id
  *
  * @return string
  */
 protected function generateId() : string
 {
     return sha1(Strings::generateRandom(24) . uniqid('', true) . microtime(true));
 }
示例#5
0
文件: SvgEngine.php 项目: fixin/fixin
 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;
 }
示例#6
0
文件: Item.php 项目: 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;
 }
示例#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);
 }