/** * Method to run the application routines. Most likely you will want to instantiate a controller * and execute it, or perform some sort of task directly. * * @return void * * @since 1.0 */ protected function doExecute() { $package = $this->io->getArgument(0); $class = $this->io->getArgument(1); $class = StringNormalise::toClassNamespace($class); if (!class_exists($class)) { $class = 'Windwalker\\' . ucfirst($package) . '\\' . $class; } if (!class_exists($class)) { $this->stop('Class not exists: ' . $class); } $packagePath = WINDWALKER_ROOT . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $package; $classPath = ReflectionHelper::getPath($class); $testPath = $packagePath . DIRECTORY_SEPARATOR . 'Test'; $testClass = $this->io->getArgument(2, ReflectionHelper::getShortName($class) . 'Test'); $testClass = StringNormalise::toClassNamespace($testClass); $testFile = $testPath . DIRECTORY_SEPARATOR . $testClass . '.php'; $realTestClass = 'Windwalker\\' . ucfirst($package) . '\\Test\\' . $testClass; $autoload = WINDWALKER_ROOT . '/vendor/autoload.php'; $command = sprintf('vendor/phpunit/phpunit-skeleton-generator/phpunit-skelgen generate-test --bootstrap="%s" %s %s %s %s', $autoload, $class, $classPath, $realTestClass, $testFile); $command = 'php ' . WINDWALKER_ROOT . '/' . $command; if (!defined('PHP_WINDOWS_VERSION_MAJOR')) { // Replace '\' to '\\' in MAC $command = str_replace('\\', '\\\\', $command); } \Windwalker\Filesystem\Folder::create(dirname($testFile)); $this->exec($command); }
/** * Execute this command. * * @return int * * @since 2.0 */ protected function doExecute() { $package = $this->getArgument(0); if (!$package) { throw new WrongArgumentException('Please enter package name.'); } $package = ConsoleHelper::getAllPackagesResolver()->getPackage($package); if (!$package) { throw new \InvalidArgumentException(sprintf('Package: %s not found', $this->getArgument(0))); } $recordClass = $this->getArgument(1); if (!$recordClass) { throw new WrongArgumentException('Please enter record name or class.'); } $recordClass = StringNormalise::toClassNamespace($recordClass); $pkgNamespace = ReflectionHelper::getNamespaceName($package); if (!class_exists($recordClass)) { $recordClass = $pkgNamespace . '\\Record\\' . ucfirst($recordClass) . 'Record'; } $table = null; if (class_exists($recordClass)) { try { /** @var Record $record */ $record = new $recordClass(); $table = $record->getTableName(); } catch (\Exception $e) { // Nothing } } if ($this->getArgument(2)) { $table = $this->getArgument(2); } $columns = Ioc::getDatabase()->getTable($table, true)->getColumnDetails(true); $fields = []; $dataType = Ioc::getDatabase()->getTable($table)->getDataType(); foreach ($columns as $column) { $fields[] = ['name' => $column->Field, 'type' => $dataType::getPhpType(explode('(', $column->Type)[0])]; } // Prepare Trait name $name = end(explode('\\', $recordClass)); $name = str_replace('Record', '', $name); $shortName = ucfirst($name) . 'DataTrait'; $data = ['package_namespace' => $pkgNamespace . '\\Record\\Traits', 'short_name' => $shortName, 'columns' => $fields]; $content = (new Edge(new EdgeStringLoader()))->render($this->getTemplate(), $data); $file = $package->getDir() . '/Record/Traits/' . $shortName . '.php'; if (is_file($file) && !(new BooleanPrompter())->ask('File: <comment>' . $file . '</comment> exists, do you want to override it? [N/y]: ', false)) { throw new \RuntimeException(' Canceled...'); } File::write($file, $content); $this->out()->out('Writing file: <info>' . $file . '</info> success.'); return true; }
/** * onAfterRouting * * @param Event $event * * @return void */ public function onAfterRouting(Event $event) { /** @var WebApplication $app */ $app = $event['app']; $package = $app->getPackage(); // In Warder if ($this->warder->isEnabled()) { RecordResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '/Admin/Record', PriorityQueue::LOW); DataMapperResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '/Admin/DataMapper', PriorityQueue::LOW); FieldDefinitionResolver::addNamespace(ReflectionHelper::getNamespaceName($package) . '/Form'); } // Frontend if ($this->warder->isFrontend()) { $package->getMvcResolver()->addNamespace(ReflectionHelper::getNamespaceName($this->warder), PriorityQueue::BELOW_NORMAL); FieldDefinitionResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '\\Form'); } elseif ($this->warder->isAdmin()) { $package->getMvcResolver()->addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '\\Admin', PriorityQueue::BELOW_NORMAL); FieldDefinitionResolver::addNamespace(ReflectionHelper::getNamespaceName($this->warder) . '\\Admin\\Form'); } }
/** * normalizeBacktrace * * @param array $trace * * @return array */ public static function normalizeBacktrace(array $trace) { $trace = new Data($trace); $args = []; foreach ($trace['args'] as $arg) { if (is_array($arg)) { $arg = 'Array'; } elseif (is_object($arg)) { $arg = ReflectionHelper::getShortName($arg); } elseif (is_string($arg)) { if (Utf8String::strlen($arg) > 20) { $arg = Utf8String::substr($arg, 0, 20) . '...'; } $arg = StringHelper::quote($arg); } elseif (is_null($arg)) { $arg = 'NULL'; } elseif (is_bool($arg)) { $arg = $arg ? 'TRUE' : 'FALSE'; } $args[] = $arg; } return array('file' => $trace['file'] ? $trace['file'] . ' (' . $trace['line'] . ')' : null, 'function' => ($trace['class'] ? $trace['class'] . $trace['type'] : null) . $trace['function'] . sprintf('(%s)', implode(', ', $args))); }
/** * prepareExecute * * @return void */ protected function prepareExecute() { $element = $this->getArgument(1); $client = strtolower($this->getOption('c')); $class = $this->getOption('class'); if ($element) { list($type, $name, $group) = array_values(ExtensionHelper::extractElement($element)); if ($client == 'admin') { $client = 'administrator'; } if ($type == 'plugin') { $client = 'site'; } elseif ($type == 'component') { $client = 'administrator'; } } $path = JPATH_ROOT . '/resources/seeders'; $classPath = $path . '/' . $class . '.php'; if (!file_exists($classPath) && $element) { $path = PathHelper::get($element, $client); $classPath = $path . '/src/' . ucfirst($name) . '/Seed/' . $class . '.php'; } if (file_exists($classPath)) { include_once $classPath; } $className = $class; if (!class_exists($className)) { $className = sprintf('%s\\Seed\\%s', ucfirst($name), ucfirst($class)); } if (!class_exists($className)) { throw new \UnexpectedValueException('Class: ' . $class . ' not found.'); } // Auto include classes $path = dirname(ReflectionHelper::getPath($className)); $files = \JFolder::files($path, '.', false, true); /** @var \SplFileInfo $file */ foreach ($files as $file) { $file = new \SplFileInfo($file); \JLoader::register($file->getBasename('.php'), $file->getPathname()); } $this->app->set('seed.class', $className); }