Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 public function write()
 {
     $pdo = $this->database->getConnection();
     $tables = $pdo->select(sprintf("SELECT TABLE_NAME as `table`, COLUMN_NAME as pk FROM information_schema.columns WHERE table_schema = '%s' AND COLUMN_KEY = 'PRI'", $pdo->getDatabaseName()));
     foreach ($tables as $table) {
         $name = $table->table;
         if (!$this->resolver->getModel($name)) {
             $path = sprintf('%s/app/Model/%s.php', $this->bootLoader->getBaseDir(), ucfirst(Str::camel(Str::singular("{$name}"))));
             if (!file_exists($path)) {
                 $this->writer->write($path, ['class' => $this->utils->filename($path), 'table' => $table->table, 'pk' => $table->pk], 'Created new model');
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param array $contents - ['san.txt' => '@san.txt', 'string.txt' => 'anything can be here']
  * @param string $zipFile
  *
  * @return string
  */
 public function create(array $contents = [], string $zipFile = '')
 {
     $zip = new ZipArchive();
     $file = sprintf('%s/%s.zip', $this->tmpDir->getTempDir('zip'), $this->utils->filename($zipFile) ?: Str::random(6));
     $res = $zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
     foreach ($contents as $filename => $data) {
         if (strpos($data, '@') === 0) {
             $zip->addFile(substr($data, 1), $filename);
         } else {
             $zip->addFromString($filename, preg_replace("/\r\n/", "\n", $data));
         }
     }
     $zip->close();
     return filesize($file) > 0 ? $file : false;
 }
Ejemplo n.º 5
0
    public function createItemArray(string $name, string $modelClass, string $localKey, $foreignKey = null)
    {
        $alias = $name;
        $single = sprintf('%sItem', $this->fixName($name));
        $multiple = sprintf('%sArray', $this->fixName($name));
        $joinKey = !empty($foreignKey) ? sprintf("'%s'", $foreignKey) : 'null';
        $theClass = $this->utils->filename($modelClass);
        $template = <<<EOF
            
        Minute.Models.{$multiple} = (function (_super) {
            __extends({$multiple}, _super);
            function {$multiple}(parent) {
                _super.call(this, Minute.Models.{$single}, parent, '{$alias}', '{$theClass}', '{$localKey}', {$joinKey});
            }
            return {$multiple};
        }(Minute.Items));

EOF;
        return $template;
    }
Ejemplo n.º 6
0
 public function index(RouteEx $_route)
 {
     $folders = $this->resolver->find('App\\Controller\\Cron');
     $controllers = [];
     foreach ($folders as $folder) {
         $classes = glob("{$folder}/*.php");
         foreach ($classes as $classPath) {
             $class = sprintf('\\App\\Controller\\Cron\\%s', $this->utils->filename($classPath));
             if (class_exists($class)) {
                 if ($reflector = new ReflectionClass($class)) {
                     foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
                         if (!preg_match('/^\\_/', $method->name)) {
                             $controller = ['type' => ucwords(basename(dirname($classPath, 4))), 'value' => sprintf("%s@%s", $method->class, $method->name), 'name' => sprintf("%s@%s", $this->utils->filename($method->class), $method->name)];
                             array_push($controllers, $controller);
                         }
                     }
                 }
             }
         }
     }
     return (new View())->with(new Helper('NyaSelect'))->set('controllers', $controllers);
 }