Пример #1
0
 public function newController($path, $controller)
 {
     $namespace = $this->utils->dosPath($this->utils->dirname($controller));
     $class = $this->utils->filename($controller);
     if ($this->writer->write($path, ['namespace' => $namespace === '.' ? '' : "\\{$namespace}", 'class' => $class])) {
         require_once $path;
     }
 }
Пример #2
0
 public function compile(ImportEvent $importEvent)
 {
     $results = ['constants' => [], 'handlers' => []];
     $wildcards = [];
     foreach (['constants', 'handlers'] as $type) {
         $e = $type === 'constants';
         foreach (['App', 'Minute'] as $dir) {
             $prefix = $e ? "{$dir}\\Event\\" : "{$dir}\\EventHandler\\";
             $dirs = $this->resolver->find($prefix);
             if (!empty($dirs)) {
                 $finder = new Finder();
                 $fix = function ($path, $replacement) use($prefix) {
                     return preg_replace('/\\.php$/', '', preg_replace(sprintf('/^.*%s/i', preg_quote($prefix)), $replacement, $path));
                 };
                 $files = $finder->depth('< 3')->files()->in($dirs)->name('*.php')->contains($e ? 'const ' : 'function ');
                 foreach ($files as $file) {
                     $classPath = $this->utils->dosPath((string) $file);
                     $classPath = $fix($classPath, $prefix);
                     $basename = $fix($classPath, '');
                     if ($reflector = new ReflectionClass($classPath)) {
                         if ($e) {
                             foreach ($reflector->getConstants() as $value => $constant) {
                                 $parts = explode('.', $constant);
                                 for ($i = 0, $j = count($parts) - 1; $i < $j; $i++) {
                                     $wildcard = join('.', array_slice($parts, 0, $i + 1)) . '.*';
                                     $wildcards[$wildcard] = ['name' => sprintf('%s', strtr($wildcard, '.', '_')), 'value' => $wildcard, 'group' => 'Wildcard events'];
                                 }
                                 $results['constants'][] = ['name' => sprintf('%s in %s', $this->utils->filename($value), $basename), 'value' => $constant, 'group' => $parts[0]];
                             }
                         } else {
                             foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
                                 if (!preg_match('/^\\_/', $method->name)) {
                                     $value = sprintf("%s@%s", $method->class, $method->name);
                                     $parts = explode('\\', $classPath);
                                     $results['handlers'][] = ['name' => sprintf('%s@%s', $basename, $method->name), 'value' => $value, 'group' => $parts[2] ?? 'App'];
                                 }
                             }
                         }
                     }
                 }
             }
         }
         usort($results[$type], function ($a, $b) {
             return $a['group'] === $b['group'] ? $a['value'] <=> $b['value'] : $a['group'] <=> $b['group'];
         });
     }
     usort($wildcards, function ($a, $b) {
         return $a['value'] <=> $b['value'];
     });
     foreach ($wildcards as $wildcard => $event) {
         $results['constants'][] = $event;
     }
     $importEvent->addContent($results);
 }
Пример #3
0
 protected function normalize(string $path, string $suffix = '')
 {
     $info = $this->utils->pathinfo($path);
     $class = $this->utils->dosPath(sprintf('%s%s%s', $suffix ? trim($suffix, '\\') . '\\' : '', $info['dirname'] !== '.' ? trim($info['dirname'], '\\') . '\\' : '', $info['filename']));
     return "\\{$class}";
 }