feat(deployed): add Windwalker library 2.1.18 (no-source, vetted live)

Windwalker 2.1.18 (Asika; RemoteImage dependency), vetted clean from live; branch-only upstream → deployed files.

Signed-off-by: LÁZÁR Imre <imre@illusion.hu>
Assisted-by: claude-code@claude-opus-4-8
This commit is contained in:
LÁZÁR Imre AI Agent 2026-07-16 09:48:14 +02:00
parent 9ef83175b0
commit 0ce0b265d4
1425 changed files with 153166 additions and 0 deletions

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,170 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
const _JEXEC = 1;
defined('_JEXEC') or die;
include_once __DIR__ . '/library/console.php';
define('BUILD_ROOT', realpath(__DIR__ . '/..'));
/**
* Class Build
*
* @since 1.0
*/
class Build extends \Asika\SimpleConsole\Console
{
/**
* Property name.
*
* @var string
*/
protected $name = 'windwalker-rad';
/**
* Property removes.
*
* @var array
*/
protected $ignores = array(
'/.git/*',
'/docs/*',
'/test/*',
'/.gitignore',
'/.travis.yml',
'/phpunit.xml.dist',
'/README.md',
'/update.xml'
);
protected $help = <<<HELP
[Usage] php build.php <version> [-b|--branch=Branch]
[Options]
h | help Show help information
b | branch (Optinal) Git branch to build if provided,
will back to staging after completed.
HELP;
/**
* execute
*
* @return void
*/
protected function doExecute()
{
// Prepare zip name.
$zipFile = BUILD_ROOT . '/../%s-%s.zip';
$version = $this->getArgument(0);
if (!$version)
{
throw new \Asika\SimpleConsole\CommandArgsException('Please enter a version.');
}
$branch = $this->getOption(array('b', 'branch'));
if ($branch && $branch !== 'staging')
{
$this->exec('git checkout ' . $branch);
}
$zipFile = new \SplFileInfo(static::cleanPath(sprintf($zipFile, $this->name, $version)));
$dir = new \RecursiveIteratorIterator(new RecursiveDirectoryIterator(BUILD_ROOT, FilesystemIterator::SKIP_DOTS));
// Start ZIP archive
$zip = new ZipArchive;
@unlink($zipFile->getPathname());
$zip->open($zipFile->getPathname(), ZIPARCHIVE::CREATE);
/** @var \SplFileInfo $file */
foreach ($dir as $file)
{
$file = str_replace(BUILD_ROOT . DIRECTORY_SEPARATOR , '', $file->getPathname());
if ($this->testIgnore('/' . $file))
{
continue;
}
$this->out('[Zip file] ' . $file);
$zip->addFile(str_replace('\\', '/', $file));
}
$zip->close();
if ($branch && $branch !== 'staging')
{
$this->exec('git checkout staging');
}
$this->out('Zip success to: ' . realpath($zipFile->getPathname()));
}
/**
* test
*
* @param string $string
*
* @return boolean
*/
public function testIgnore($string)
{
$match = false;
// fnmatch() only work for UNIX file path
$string = str_replace(array('/', '\\'), '/', $string);
foreach ($this->ignores as $rule)
{
// Negative
if (substr($rule, 0, 1) == '!')
{
$rule = substr($rule, 1);
if (fnmatch($rule, $string))
{
$match = false;
}
}
// Normal
else
{
if (fnmatch($rule, $string))
{
$match = true;
}
}
}
return $match;
}
/**
* cleanPath
*
* @param string $path
* @param string $ds
*
* @return string
*/
public static function cleanPath($path, $ds = DIRECTORY_SEPARATOR)
{
return str_replace(array('/', '\\'), $ds, $path);
}
}
$build = new Build;
$build->execute();

View File

@ -0,0 +1,15 @@
<?php
/**
* Part of Component Ezset files.
*
* @copyright Copyright (C) 2017 Asikart.co. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
const _JEXEC = 1;
defined('_JEXEC') or die;
return array(
'libraries/windwalker' => '.',
'media/windwalker' => 'asset',
);

View File

@ -0,0 +1,168 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2015 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later;
*/
use Joomla\Application\AbstractCliApplication;
use Windwalker\Filesystem\Path;
use Windwalker\String\StringNormalise;
use Windwalker\Utilities\Reflection\ReflectionHelper;
$autoload = __DIR__ . '/../vendor/autoload.php';
if (!is_file($autoload))
{
$autoload = __DIR__ . '/../../../autoload.php';
}
include_once $autoload;
define('WINDWALKER_ROOT', realpath(__DIR__ . '/..'));
define('WINDWALKER_CORE_ROOT', realpath(__DIR__ . '/../vendor/windwalker/core'));
/**
* Class GenTest
*
* @since 1.0
*/
class GenTest extends AbstractCliApplication
{
/**
* Property lastOutput.
*
* @var mixed
*/
protected $lastOutput = null;
/**
* Property lastReturn.
*
* @var mixed
*/
protected $lastReturn = null;
/**
* 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\\Core\\' . $package . '\\' . $class;
}
if (!class_exists($class))
{
$this->stop('Class not exists: ' . $class);
}
$classPath = ReflectionHelper::getPath($class);
$testPath = WINDWALKER_ROOT . DIRECTORY_SEPARATOR . 'test';
$testClass = $this->io->getArgument(2, ReflectionHelper::getShortName($class) . 'Test');
$testClass = StringNormalise::toClassNamespace($testClass);
$testFile = $testPath . DIRECTORY_SEPARATOR . ucfirst($package) . DIRECTORY_SEPARATOR . Path::clean($testClass) . '.php';
$realTestClass = 'Windwalker\\Core\\Test\\' . ucfirst($package) . '\\' . $testClass;
$autoload = WINDWALKER_ROOT . '/vendor/autoload.php';
$skelgen = 'vendor/phpunit/phpunit-skeleton-generator/phpunit-skelgen';
if (!is_file(WINDWALKER_ROOT . '/' . $skelgen))
{
$skelgen = '../../phpunit/phpunit-skeleton-generator/phpunit-skelgen';
}
$command = sprintf(
$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);
}
/**
* getPackagePath
*
* @param string $class
* @param string $classPath
*
* @return void
*/
protected function getPackagePath($class, $classPath)
{
$classFile = Path::clean($class) . '.php';
$classFile = substr($classFile, 11);
$this->out($classFile);
$this->out($classPath);
$packagePath = str_replace($classFile, '', $classPath);
$this->out($packagePath);
print_r($classFile);
}
/**
* Exec a command.
*
* @param string $command
* @param array $arguments
* @param array $options
*
* @return string
*/
protected function exec($command, $arguments = array(), $options = array())
{
$arguments = implode(' ', (array) $arguments);
$options = implode(' ', (array) $options);
$command = sprintf('%s %s %s', $command, $arguments, $options);
$this->out('>> ' . $command);
$return = exec(trim($command), $this->lastOutput, $this->lastReturn);
$this->out($return);
}
/**
* stop
*
* @param string $msg
*
* @return void
*/
protected function stop($msg = null)
{
if ($msg)
{
$this->out($msg);
}
$this->close();
}
}
$app = new GenTest;
$app->execute();

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,450 @@
<?php
/**
* Part of Simple Console project.
*
* @copyright Copyright (C) 2017 Simon Asika.
* @license MIT
*/
namespace Asika\SimpleConsole;
/**
* The Console class.
*
* @since 1.0
*/
class Console
{
/**
* Property executable.
*
* @var string
*/
protected $executable;
/**
* Property args.
*
* @var array
*/
protected $args = array();
/**
* Property options.
*
* @var array
*/
protected $options = array();
/**
* Property help.
*
* @var string
*/
protected $help = '';
/**
* Property helpIptions.
*
* @var array
*/
protected $helpOptions = array('h', 'help');
/**
* Property booleanMapping.
*
* @var array
*/
protected $booleanMapping = array(
0 => array('n', 'no', 'false', 0, '0', true),
1 => array('y', 'yes', 'true', 1, '1', false, null)
);
/**
* CliInput constructor.
*
* @param array $argv
*/
public function __construct($argv = null)
{
$this->parseArgv($argv ? : $_SERVER['argv']);
$this->init();
}
/**
* init
*
* @return void
*/
protected function init()
{
// Override if necessary
}
/**
* execute
*
* @param \Closure|null $callback
*
* @return int
*/
public function execute(\Closure $callback = null)
{
try
{
if ($this->getOption($this->helpOptions))
{
$this->out($this->getHelp());
return 0;
}
if ($callback)
{
if (version_compare(PHP_VERSION, '5.4', '>='))
{
$callback = $callback->bindTo($this);
}
$result = call_user_func($callback, $this);
}
else
{
$result = $this->doExecute();
}
}
catch (\Exception $e)
{
$result = $this->handleException($e);
}
catch (\Throwable $e)
{
$result = $this->handleException($e);
}
if ($result === true)
{
$result = 0;
}
elseif ($result === false)
{
$result = 255;
}
else
{
$result = (bool) $result;
}
return (int) $result;
}
/**
* doExecute
*
* @return void
*/
protected function doExecute()
{
// Please override this method.
}
/**
* getHelp
*
* @return string
*/
protected function getHelp()
{
return trim($this->help);
}
/**
* handleException
*
* @param \Exception|\Throwable $e
*
* @return void
*/
protected function handleException($e)
{
$v = $this->getOption('v');
if ($e instanceof CommandArgsException)
{
$this->err('[Warning] ' . $e->getMessage())
->err()
->err($this->getHelp());
}
else
{
$this->err('[Error] ' . $e->getMessage());
}
if ($v)
{
$this->err('[Backtrace]:')
->err($e->getTraceAsString());
}
$code = $e->getCode();
return $code === 0 ? 255 : $code;
}
/**
* getArgument
*
* @param int $offset
* @param mixed $default
*
* @return mixed|null
*/
public function getArgument($offset, $default = null)
{
if (!isset($this->args[$offset]))
{
return $default;
}
return $this->args[$offset];
}
/**
* setArgument
*
* @param int $offset
* @param mixed $value
*
* @return static
*/
public function setArgument($offset, $value)
{
$this->args[$offset] = $value;
return $this;
}
/**
* getOption
*
* @param string|array $name
* @param mixed $default
*
* @return mixed|null
*/
public function getOption($name, $default = null)
{
$name = (array) $name;
foreach ($name as $n)
{
if (isset($this->options[$n]))
{
return $this->options[$n];
}
}
return $default;
}
/**
* setOption
*
* @param string $name
* @param mixed $value
*
* @return static
*/
public function setOption($name, $value)
{
$name = (array) $name;
foreach ($name as $n)
{
$this->options[$n] = $value;
}
return $this;
}
/**
* out
*
* @param string $text
* @param boolean $nl
*
* @return Build
*/
public function out($text = null, $nl = true)
{
fwrite(STDOUT, $text . ($nl ? "\n" : ''));
return $this;
}
/**
* err
*
* @param string $text
* @param boolean $nl
*
* @return Build
*/
public function err($text = null, $nl = true)
{
fwrite(STDERR, $text . ($nl ? "\n" : ''));
return $this;
}
/**
* in
*
* @param string $ask
* @param mixed $default
*
* @return string
*/
public function in($ask = '', $default = null, $bool = false)
{
$this->out($ask, false);
$in = rtrim(fread(STDIN, 8192), "\n\r");
if ($bool)
{
$in = $in === '' ? $default : $in;
return (bool) $this->mapBoolean($in);
}
return $in === '' ? (string) $default : $in;
}
/**
* mapBoolean
*
* @param string $in
*
* @return bool
*/
public function mapBoolean($in)
{
$in = strtolower((string) $in);
if (in_array($in, $this->booleanMapping[0], true))
{
return false;
}
if (in_array($in, $this->booleanMapping[1], true))
{
return true;
}
return null;
}
/**
* exec
*
* @param string $command
*
* @return static
*/
protected function exec($command)
{
$this->out('>> ' . $command);
$return = exec($command);
$this->out($return . "\n");
return $this;
}
/**
* parseArgv
*
* @param array $argv
*
* @return void
*/
protected function parseArgv($argv)
{
$this->executable = array_shift($argv);
$out = array();
for ($i = 0, $j = count($argv); $i < $j; $i++)
{
$arg = $argv[$i];
// --foo --bar=baz
if (substr($arg, 0, 2) === '--')
{
$eqPos = strpos($arg, '=');
// --foo
if ($eqPos === false)
{
$key = substr($arg, 2);
// --foo value
if ($i + 1 < $j && $argv[$i + 1][0] !== '-')
{
$value = $argv[$i + 1];
$i++;
}
else
{
$value = isset($out[$key]) ? $out[$key] : true;
}
$out[$key] = $value;
}
// --bar=baz
else
{
$key = substr($arg, 2, $eqPos - 2);
$value = substr($arg, $eqPos + 1);
$out[$key] = $value;
}
}
// -k=value -abc
elseif (substr($arg, 0, 1) === '-')
{
// -k=value
if (substr($arg, 2, 1) === '=')
{
$key = substr($arg, 1, 1);
$value = substr($arg, 3);
$out[$key] = $value;
}
// -abc
else
{
$chars = str_split(substr($arg, 1));
foreach ($chars as $char)
{
$key = $char;
$out[$key] = isset($out[$key]) ? $out[$key] + 1 : 1;
}
// -a a-value
if ((count($chars) === 1) && ($i + 1 < $j) && ($argv[$i + 1][0] !== '-'))
{
$out[$key] = $argv[$i + 1];
$i++;
}
}
}
// Plain-arg
else
{
$this->args[] = $arg;
}
}
$this->options = $out;
}
}
class CommandArgsException extends \RuntimeException {}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,128 @@
#!/bin/sh php
<?php
/**
* Asikart Joomla! Extensions extension link script.
*
* @copyright (c) 2014 Asikart.com. All rights reserved.
*/
include_once __DIR__ . '/library/console.php';
/**
* The Makelink class.
*
* @since 1.0
*/
class Makelink extends \Asika\SimpleConsole\Console
{
/**
* Property help.
*
* @var string
*/
protected $help = <<<HELP
[Usage] php makelink <joomla_dir>
h | help Show help info.
f | force Force replace exists dir.
HELP;
/**
* doExecute
*
* @return bool
*/
protected function doExecute()
{
$joomlaDir = $this->getArgument(0);
// Check Arguments
if (!$joomlaDir)
{
throw new \Asika\SimpleConsole\CommandArgsException('Please give me Joomla path.');
}
// Check Joomla dir
if (!is_dir($joomlaDir . '/libraries/joomla'))
{
throw new \RuntimeException(sprintf('%s is not a Joomla dir.', $joomlaDir));
}
// Prepare some variables
$windows = defined('PHP_WINDOWS_VERSION_MAJOR');
$root = dirname(__DIR__);
$dirs = include __DIR__ . '/dirs.php';
// Do bakup and create link
foreach ($dirs as $dir => $target)
{
$dir = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $dir);
$target = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $target);
if ($windows)
{
if (is_dir("{$joomlaDir}\\{$dir}"))
{
if ($this->getOption(array('f', 'force')))
{
$this->exec("rmdir {$joomlaDir}\\{$dir}");
}
else
{
$this->exec("powershell.exe mv {$joomlaDir}\\{$dir} {$joomlaDir}\\{$dir}.bak");
}
}
$this->exec("mklink /D {$joomlaDir}\\{$dir} {$root}\\{$target}");
$this->out("Make link {$joomlaDir}\\{$dir} to {$root}\\{$target}");
}
else
{
if (is_dir("{$joomlaDir}/{$dir}"))
{
if ($this->getOption(array('f', 'force')))
{
exec("rm -rf {$joomlaDir}/{$dir}");
}
else
{
exec("mv {$joomlaDir}/{$dir} {$joomlaDir}/{$dir}.bak");
}
}
$this->exec("ln -s {$root}/{$target} {$joomlaDir}/{$dir}");
$this->out("Make link {$root}/{$target} to {$joomlaDir}/{$dir}");
}
}
$this->createBinFile($joomlaDir);
return true;
}
/**
* createBinFile
*
* @param string $joomlaDir
*
* @return void
*/
protected function createBinFile($joomlaDir)
{
include_once __DIR__ . '/../src/System/Installer/WindwalkerInstaller.php';
\Windwalker\System\Installer\WindwalkerInstaller::createBinFile($joomlaDir);
$this->out('Bin file created.');
\Windwalker\System\Installer\WindwalkerInstaller::createBundleDir($joomlaDir);
$this->out('Bundle folder created.');
}
}
$app = new Makelink;
$app->execute();

View File

@ -0,0 +1,217 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
const _JEXEC = 1;
defined('_JEXEC') or die;
include_once __DIR__ . '/library/console.php';
define('BUILD_ROOT', realpath(__DIR__ . '/..'));
/**
* Class Build
*
* @since 1.0
*/
class Release extends \Asika\SimpleConsole\Console
{
/**
* Property manifests.
*
* @var array
*/
protected $manifests = array(
'windwalker.xml'
);
/**
* Property stagingBranch.
*
* @var string
*/
protected $stagingBranch = 'staging';
/**
* Property masterBranch.
*
* @var string
*/
protected $masterBranch = 'master';
/**
* Property dry.
*
* @var bool
*/
protected $dry = false;
/**
* Property force.
*
* @var bool
*/
protected $force = false;
/**
* Property help.
*
* @var string
*/
protected $help = <<<HELP
[Usage] php release.php <version> <next_version>
[Options]
h | help Show help information
d | dry-run Dry run.
f | force Force operation.
HELP;
/**
* execute
*
* @return void
* @throws \Asika\SimpleConsole\CommandArgsException
*/
protected function doExecute()
{
$this->dry = $this->getOption(array('d', 'dry-run'));
$this->force = $this->getOption(array('f', 'force'));
$version = $this->getArgument(0);
$nextVersion = $this->getArgument(1);
$f = $this->force ? ' -f' : '';
if (!$version)
{
throw new \Asika\SimpleConsole\CommandArgsException('Please enter a version.');
}
if (!$this->dry)
{
$this->exec('git checkout ' . $this->masterBranch);
$this->exec('git merge ' . $this->stagingBranch);
$this->exec('git tag ' . $version . $f);
$this->exec('git checkout ' . $this->stagingBranch);
}
if (!$nextVersion)
{
$v = array_pad(explode('.', $version), 3, 0);
$v[2]++;
$nextVersion = implode('.', $v);
}
$this->upNewVersions($nextVersion);
if (!$nextVersion)
{
$v = array_pad(explode('.', $version), 3, 0);
$v[0] += 2;
$nextVersion = implode('.', $v);
}
$this->upVersions($nextVersion);
if (!$this->dry)
{
$this->exec(sprintf('git commit -am "Prepare for %s development."', $nextVersion));
$this->exec('git push origin ' . $this->stagingBranch . ' ' . $this->masterBranch . $f);
$this->exec('git push origin --tags' . $f);
}
$this->out()->out('Release to version: ' . $version . ' and prepared for ' . $nextVersion);
}
/**
* upVersions
*
* @param string $version
*
* @return void
*/
protected function upVersions($version)
{
$manifests = $this->manifests;
foreach ($manifests as $manifest)
{
$file = BUILD_ROOT . '/' . $manifest;
if (is_file($file))
{
$xml = file_get_contents($file);
$xml = preg_replace('/<version>([\w.]+)<\/version>/', '<version>' . $version . '</version>', $xml);
$this->out(sprintf('[Replace version] %s', $manifest));
if (!$this->dry)
{
file_put_contents($file, $xml);
}
}
}
}
/**
* upVersions
*
* @param string $version
*
* @return void
*/
protected function upNewVersions($version)
{
$manifests = $this->manifests;
foreach ($manifests as $manifest)
{
$file = BUILD_ROOT . '/' . $manifest;
if (is_file($file))
{
$xml = file_get_contents($file);
$xml = preg_replace('/<newversion>([\w.]+)<\/newversion>/', '<newversion>' . $version . '</newversion>', $xml);
$this->out(sprintf('[Replace newversion] %s', $manifest));
if (!$this->dry)
{
file_put_contents($file, $xml);
}
}
}
}
/**
* cleanPath
*
* @param string $path
* @param string $ds
*
* @return string
*/
public static function cleanPath($path, $ds = DIRECTORY_SEPARATOR)
{
return str_replace(array('/', '\\'), $ds, $path);
}
}
$build = new Release;
$build->execute();

View File

@ -0,0 +1,58 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
use Joomla\CMS\Factory;
// We are a valid entry point.
const _JEXEC = 1;
// Configure error reporting to maximum for CLI output.
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/../../defines.php'))
{
require_once dirname(__DIR__) . '/../../defines.php';
}
if (!defined('JPATH_BASE'))
{
define('JPATH_BASE', realpath(dirname(__DIR__) . '/../..'));
}
if (!defined('_JDEFINES'))
{
require_once JPATH_BASE . '/includes/defines.php';
}
define('WINDWALKER_CONSOLE', __DIR__);
// Get the framework.
require_once JPATH_BASE . '/includes/framework.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
restore_exception_handler();
// Windwalker init
include_once WINDWALKER_CONSOLE . '/../src/init.php';
// Import the configuration.
require_once JPATH_CONFIGURATION . '/configuration.php';
// System configuration.
$config = new JConfig;
$console = \Windwalker\DI\Container::getInstance()->get('app');
Factory::$application = $console;
$console->setDescription(null)
->execute();

View File

@ -0,0 +1,29 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action;
use Windwalker\DI\Container;
/**
* Class AbstractAction
*
* @since 1.0
*/
abstract class AbstractAction extends \Muse\Action\AbstractAction
{
/**
* Constructor.
*
* @param Container $container
*/
public function __construct(Container $container = null)
{
$this->container = $container ? : Container::getInstance();
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component;
use GeneratorBundle\Action\AbstractAction;
use Windwalker\Filesystem\Folder;
/**
* Class ConvertTemplateAction
*
* @since 1.0
*/
class ConvertTemplateAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed|void
*/
public function doExecute()
{
// Flip replace array because we want to convert template.
$replace = array_flip($this->replace);
foreach ($replace as &$val)
{
$val = '{{' . $val . '}}';
}
// Flip src and dest because we want to convert template.
$src = $this->config['dir.src'];
$dest = $this->config['dir.dest'];
// Remove dir first
if (is_dir($dest))
{
Folder::delete($dest);
}
$this->container->get('operator.convert')->copy($src, $dest, $replace);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component;
use GeneratorBundle\Action\AbstractAction;
/**
* Class CopyBasefilesAction
*
* @since 1.0
*/
class CopyAllAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
public function doExecute()
{
$copyOperator = $this->container->get('operator.copy');
$config = $this->config;
$copyOperator->copy($config['dir.src'], $config['dir.dest'], (array) $config['replace']);
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component;
use GeneratorBundle\Action\AbstractAction;
use Windwalker\String\SimpleTemplate;
use Windwalker\String\StringHelper;
/**
* Class ImportSqlAction
*
* @since 1.0
*/
class CopyLanguageAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
public function doExecute()
{
try
{
$lanDir = new \DirectoryIterator($this->config['dir.src'] . '/language');
}
catch (\UnexpectedValueException $e)
{
return;
}
// Each languages
foreach ($lanDir as $dir)
{
if ($lanDir->isDot() || $lanDir->isFile())
{
continue;
}
$this->handleINIFile($dir->getBasename());
}
}
/**
* handleINIFile
*
* @param string $dir
*
* @return void
*/
protected function handleINIFile($dir)
{
$src = $this->config['dir.src'];
$dest = $this->config['dir.dest'];
$fileName = $dir . '.' . $this->config['element'] . '%s.ini';
$mainINI = $this->findIniBySuffix($dir, 'main');
$sysINI = $this->findIniBySuffix($dir, 'sys');
// Main file
$targetFile = $dest . '/language/' . $dir . '/' . sprintf($fileName, '');
if (strpos(file_get_contents($targetFile), '; ' . $this->config['replace.controller.item.name.cap']) === false)
{
$mainINI = $this->getSubsystemText($mainINI);
$fp = fopen($targetFile, 'a+');
fwrite($fp, "\n\n\n" . $mainINI);
fclose($fp);
$this->controller->out('Write subsystem ini to: ' . $targetFile);
}
// Sys file
$targetFile = $dest . '/language/' . $dir . '/' . sprintf($fileName, '.sys');
if (strpos(file_get_contents($targetFile), '; ' . $this->config['replace.controller.item.name.cap']) === false)
{
$sysINI = $this->getSubsystemText($sysINI);
$fp = fopen($targetFile, 'a+');
fwrite($fp, "\n\n\n" . $sysINI);
fclose($fp);
$this->controller->out('Write subsystem ini to: ' . $targetFile);
}
}
/**
* findIniBySuffix
*
* @param string $dir
* @param string $suffix
*
* @return mixed
*/
protected function findIniBySuffix($dir, $suffix = 'main')
{
try
{
$files = new \FilesystemIterator($this->config['dir.src'] . '/language/' . $dir);
}
catch (\UnexpectedValueException $e)
{
exit('No such file: ' . $this->config['dir.src'] . '/language' . $dir);
}
foreach ($files as $file)
{
$name = $file->getBasename();
$extract = explode('.', $name);
if ($suffix === 'main' && count($extract) === 5)
{
return $file;
}
elseif (isset($extract[4]) && $extract[4] === $suffix)
{
return $file;
}
}
return null;
}
/**
* getSubsystemText
*
* @param \SplFileinfo $file
*
* @return string
*/
protected function getSubsystemText(\SplFileinfo $file)
{
$text = file_get_contents($file);
$text = substr($text, strpos($text, '; {{controller.item.name.cap}}') - strlen($text));
return SimpleTemplate::render($text, $this->config['replace']);
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component;
use GeneratorBundle\Action\AbstractAction;
use Windwalker\DI\Container;
use Windwalker\String\SimpleTemplate;
use Windwalker\String\StringHelper;
/**
* Class ImportSqlAction
*
* @since 1.0
*/
class ImportSqlAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
public function doExecute()
{
// Load SQL file.
@$installFile = file_get_contents($this->config['dir.src'] . '/sql/install.sql');
@$uninstallFile = file_get_contents($this->config['dir.src'] . '/sql/uninstall.sql');
$installSql = SimpleTemplate::render($installFile, $this->config['replace']);
$uninstallSql = SimpleTemplate::render($uninstallFile, $this->config['replace']);
// Prevent import twice
$table = '#__' . $this->config['name'] . '_' . $this->config['replace.controller.list.name.lower'];
$db = Container::getInstance()->get('db');
try
{
$db->getTableColumns($table);
}
catch (\RuntimeException $e)
{
// Import sql
$this->controller->out('Importing SQL to table: ' . $table);
$this->executeSql($installSql);
$this->controller->out('Imported');
}
if (!strpos($installSql, $table))
{
// Write SQL file to project.
@$fp = fopen($this->config['dir.dest'] . '/sql/install.sql', 'a+');
@fputs($fp, "\n\n\n" . $installSql);
@fclose($fp);
@$fp = fopen($this->config['dir.dest'] . '/sql/uninstall.sql', 'a+');
@fputs($fp, "\n\n" . $uninstallSql);
@fclose($fp);
}
}
/**
* executeSql
*
* @param string $sql
*
* @return void
*/
protected function executeSql($sql)
{
$db = Container::getInstance()->get('db');
$queries = $db->splitSql($sql);
foreach ($queries as $query)
{
if (!trim($query))
{
continue;
}
$db->setQuery($query)->execute();
}
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component\Subsystem;
use GeneratorBundle\Action\AbstractAction;
/**
* Class PrepareAction
*
* @since 1.0
*/
class CopyItemAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
protected function doExecute()
{
$copyOperator = $this->container->get('operator.copy');
$src = $this->config['dir.src'];
$dest = $this->config['dir.dest'];
$item = $this->config['item_name'];
$files = array(
'controller/%s',
'model/form/%s.xml',
'model/%s.php',
'router/handler/%s.php',
'view/%s'
);
foreach ($files as $file)
{
$file = sprintf($file, $item);
if (!file_exists($src . '/' . $file))
{
continue;
}
$copyOperator->copy(
$src . '/' . $file,
$dest . '/' . $file,
$this->config['replace']
);
}
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component\Subsystem;
use GeneratorBundle\Action\AbstractAction;
/**
* Class PrepareAction
*
* @since 1.0
*/
class CopyListAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
protected function doExecute()
{
$copyOperator = $this->container->get('operator.copy');
$src = $this->config['dir.src'];
$dest = $this->config['dir.dest'];
$list = $this->config['list_name'];
$files = array(
'controller/%s',
'model/form/%s',
'model/%s.php',
'router/handler/%s.php',
'view/%s'
);
foreach ($files as $file)
{
$file = sprintf($file, $list);
if (!file_exists($src . '/' . $file))
{
continue;
}
$copyOperator->copy(
$src . '/' . $file,
$dest . '/' . $file,
$this->config['replace']
);
}
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Component\Subsystem;
use GeneratorBundle\Action\AbstractAction;
use GeneratorBundle\Action\Component;
/**
* Class PrepareAction
*
* @since 1.0
*/
class PrepareAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
protected function doExecute()
{
$copyOperator = $this->container->get('operator.copy');
$src = $this->config['dir.src'];
$dest = $this->config['dir.dest'];
$files = array(
'model/field'
);
if ($this->config['client'] === 'administrator')
{
$files[] = 'table/' . $this->config['item_name'] . '.php';
$files[] = 'src/{{extension.name.cap}}/Mapper/{{controller.item.name.cap}}Mapper.php';
}
foreach ($files as $file)
{
if (!file_exists($src . '/' . $file))
{
continue;
}
$copyOperator->copy(
$src . '/' . $file,
$dest . '/' . $file,
$this->config['replace']
);
}
$this->controller->doAction(new Component\ImportSqlAction);
$this->controller->doAction(new Component\CopyLanguageAction);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,49 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action;
use Windwalker\Filesystem\Folder;
/**
* Class ConvertTemplateAction
*
* @since 1.0
*/
class ConvertTemplateAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed|void
*/
public function doExecute()
{
// Flip replace array because we want to convert template.
$replace = array_flip($this->replace);
foreach ($replace as &$val)
{
$val = '{{' . $val . '}}';
}
// Flip src and dest because we want to convert template.
$src = $this->config['dir.src'];
$dest = $this->config['dir.dest'];
if (!is_dir($src))
{
throw new \RuntimeException(sprintf('Extension "%s" in %s not exists', $this->config['element'], $this->config['client']));
}
// Remove dir first
Folder::delete($dest);
$this->container->get('operator.convert')->copy($src, $dest, $replace);
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action;
/**
* Class CopyAllAction
*
* @since 1.0
*/
class CopyAllAction extends AbstractAction
{
/**
* doExecute
*
* @throws \RuntimeException
* @return mixed
*/
public function doExecute()
{
$copyOperator = $this->container->get('operator.copy');
$config = $this->config;
if (!is_dir($config['dir.tmpl']))
{
throw new \RuntimeException(sprintf('Template "%s" of %s not exists', $config['template'], $config['extension']));
}
$copyOperator->copy($config['dir.src'], $config['dir.dest'], (array) $config['replace']);
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Action\Module;
use GeneratorBundle\Action\AbstractAction;
use Windwalker\Filesystem\File;
use Windwalker\String\SimpleTemplate;
/**
* Class ReplaceXmlClientAction
*
* @since 1.0
*/
class ReplaceXmlClientAction extends AbstractAction
{
/**
* doExecute
*
* @return mixed
*/
protected function doExecute()
{
$xml = $this->config['dir.dest'] . '/{{extension.element.lower}}.xml';
$content = file_get_contents($xml);
$content = str_replace('client="site"', '{{module.client}}', $content);
File::write($xml, $content);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,38 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later;
*/
namespace GeneratorBundle\Action\Test;
use GeneratorBundle\Action\AbstractAction;
use Muse\Filesystem\Folder;
use Windwalker\String\SimpleTemplate;
use Windwalker\String\StringHelper;
/**
* The GenClassAction class.
*
* @since 2.1
*/
class GenClassAction extends AbstractAction
{
/**
* Do this execute.
*
* @return mixed
*/
protected function doExecute()
{
$tmpl = file_get_contents(GENERATOR_BUNDLE_PATH . '/Template/test/testClass.php');
$file = SimpleTemplate::render($tmpl, $this->replace);
Folder::create(dirname($this->config['replace.test.class.file']));
file_put_contents($this->config['replace.test.class.file'], $file);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,76 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Add;
use GeneratorBundle\Command\Generator\Add\AddItem\AddItemCommand;
use GeneratorBundle\Command\Generator\Add\AddList\AddListCommand;
use GeneratorBundle\Command\Generator\Add\Subsystem\SubsystemCommand;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Add
*
* @since 2.0
*/
class AddCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'add';
/**
* The command description.
*
* @var string
*/
protected $description = 'Add new controller view model system classes(only component).';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'add <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
$this->addCommand(new AddItemCommand);
$this->addCommand(new AddListCommand);
$this->addCommand(new SubsystemCommand);
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
return parent::doExecute();
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Add\AddItem;
use GeneratorBundle\Controller\GeneratorController;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Item
*
* @since 2.0
*/
class AddItemCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'item';
/**
* The command description.
*
* @var string
*/
protected $description = 'Add a singular MVC group for item CRUD.';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'item <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
// $this->addArgument();
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
$generator = new GeneratorController($this);
$generator->setTask('add.item')->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,74 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Add\AddList;
use GeneratorBundle\Controller\GeneratorController;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class List
*
* @since 2.0
*/
class AddListCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'list';
/**
* The command description.
*
* @var string
*/
protected $description = 'Add a plural controller to show list page.';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'list <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
// $this->addArgument();
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
$generator = new GeneratorController($this);
$generator->setTask('add.list')->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,74 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Add\Subsystem;
use GeneratorBundle\Controller\GeneratorController;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Subsystem
*
* @since 2.0
*/
class SubsystemCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'subsystem';
/**
* The command description.
*
* @var string
*/
protected $description = "Sub system contains item and list two controller\n to support CRUD a table.";
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'subsystem <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
// $this->addArgument();
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
$generator = new GeneratorController($this);
$generator->setTask('add.subsystem')->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,74 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Convert;
use GeneratorBundle\Controller\GeneratorController;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Convert
*
* @since 2.0
*/
class ConvertCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'convert';
/**
* The command description.
*
* @var string
*/
protected $description = 'Convert an extension back to a template.';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'convert <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
// $this->addArgument();
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
$generator = new GeneratorController($this);
$generator->setTask('template.convert')->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,87 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator;
use GeneratorBundle\Command\Generator\Add\AddCommand;
use GeneratorBundle\Command\Generator\Convert\ConvertCommand;
use GeneratorBundle\Command\Generator\Init\InitCommand;
use GeneratorBundle\Command\Generator\Test\TestCommand;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Genarator
*
* @since 2.0
*/
class GeneratorCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'generator';
/**
* The command description.
*
* @var string
*/
protected $description = 'Extension generator.';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'generator <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
parent::initialise();
$this->addCommand(new InitCommand);
$this->addCommand(new ConvertCommand);
$this->addCommand(new AddCommand);
$this->addCommand(new TestCommand);
$this->addGlobalOption('c')
->alias('client')
->description('Site or administrator (admin)');
$this->addGlobalOption('t')
->alias('tmpl')
->defaultValue('default')
->description('Using template.');
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
return parent::doExecute();
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Init;
use GeneratorBundle\Controller\GeneratorController;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Init
*
* @since 2.0
*/
class InitCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'init';
/**
* The command description.
*
* @var string
*/
protected $description = 'Init a new extension.';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'init <cmd><command></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
// $this->addArgument();
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
$generator = new GeneratorController($this);
$generator->setTask('init')->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,87 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Command\Generator\Test;
use GeneratorBundle\Controller\GeneratorController;
use GeneratorBundle\Controller\TestGeneratorController;
use Windwalker\Console\Command\Command;
defined('WINDWALKER') or die;
/**
* Class Init
*
* @since 2.0
*/
class TestCommand extends Command
{
/**
* An enabled flag.
*
* @var bool
*/
public static $isEnabled = true;
/**
* Console(Argument) name.
*
* @var string
*/
protected $name = 'test';
/**
* The command description.
*
* @var string
*/
protected $description = 'Generate test cases.';
/**
* The usage to tell user how to use this command.
*
* @var string
*/
protected $usage = 'test <cmd><package></cmd> <cmd><class></cmd> <cmd><target></cmd> <option>[option]</option>';
/**
* Configure command information.
*
* @return void
*/
public function initialise()
{
$this->help(
<<<HELP
Example:
generator test Helper PathHelper
Generate to: test/Helper/PathHelper.php
generator test Helper PathHelper Foo/Bar/PathHelper
Generate to: test/Foo/Bar/PathHelper.php
HELP
);
parent::initialise();
}
/**
* Execute this command.
*
* @return int|void
*/
protected function doExecute()
{
$generator = new TestGeneratorController($this);
$generator->setTask('test')->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,103 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller;
use Muse\Controller\AbstractTaskController;
use Muse\IO\IOInterface;
use Windwalker\Filesystem\Path;
use Windwalker\Registry\Registry;
use Windwalker\Console\Command\Command;
use Windwalker\DI\Container;
use Windwalker\Helper\PathHelper;
use Windwalker\String\StringInflector;
/**
* Class AbstractJExtensionController
*
* @since 1.0
*/
abstract class AbstractJExtensionController extends AbstractTaskController
{
/**
* Property container.
*
* @var Container
*/
protected $container;
/**
* Constructor.
*
* @param \Windwalker\DI\Container $container
* @param \Muse\IO\IOInterface $io
* @param Registry $config
*/
public function __construct(Container $container, IOInterface $io, Registry $config = null)
{
// Get item & list name
$ctrl = $config['ctrl'] ? : $io->getArgument(1);
$ctrl = explode('.', $ctrl);
$inflector = StringInflector::getInstance();
if (empty($ctrl[0]))
{
$ctrl[0] = 'item';
}
if (empty($ctrl[1]))
{
$ctrl[1] = $inflector->toPlural($ctrl[0]);
}
list($itemName, $listName) = $ctrl;
$this->replace['extension.element.lower'] = strtolower($config['element']);
$this->replace['extension.element.upper'] = strtoupper($config['element']);
$this->replace['extension.element.cap'] = ucfirst($config['element']);
$this->replace['extension.name.lower'] = strtolower($config['name']);
$this->replace['extension.name.upper'] = strtoupper($config['name']);
$this->replace['extension.name.cap'] = ucfirst($config['name']);
$this->replace['controller.list.name.lower'] = strtolower($listName);
$this->replace['controller.list.name.upper'] = strtoupper($listName);
$this->replace['controller.list.name.cap'] = ucfirst($listName);
$this->replace['controller.item.name.lower'] = strtolower($itemName);
$this->replace['controller.item.name.upper'] = strtoupper($itemName);
$this->replace['controller.item.name.cap'] = ucfirst($itemName);
// Set replace to config.
foreach ($this->replace as $key => $val)
{
$config->set('replace.' . $key, $val);
}
// Set copy dir.
$config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client']));
$config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']);
$config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']);
// Replace DS
$config['dir.dest'] = Path::clean($config['dir.dest']);
$config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
$config['dir.src'] = Path::clean($config['dir.src']);
// Push container
$this->container = $container;
parent::__construct($io, $config, $this->replace);
}
}

View File

@ -0,0 +1,108 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Component;
use Muse\IO\IOInterface;
use GeneratorBundle\Controller\AbstractJExtensionController;
use Windwalker\Filesystem\Path;
use Windwalker\Registry\Registry;
use Windwalker\DI\Container;
use Windwalker\Helper\PathHelper;
/**
* Class AbstractComponentController
*
* @since 1.0
*/
abstract class AbstractComponentController extends AbstractJExtensionController
{
/**
* Constructor.
*
* @param Container $container
* @param IOInterface $io
* @param Registry $config
*/
public function __construct(Container $container, IOInterface $io, Registry $config = null)
{
parent::__construct($container, $io, $config);
// Load config json
$this->config->loadFile(__DIR__ . '/config.json');
}
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @since 12.1
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
$config = $this->config;
if (!$config['client'])
{
$config['client'] = 'site';
$this->configurePath()->doExecute();
$config['client'] = 'administrator';
$this->configurePath()->doExecute();
}
else
{
$config['client'] = ($config['client'] === 'site') ? $config['client'] : 'administrator';
$this->configurePath()->doExecute();
}
return true;
}
/**
* Do Execute.
*
* @return void
*/
abstract protected function doExecute();
/**
* configurePath
*
* @return $this
*/
protected function configurePath()
{
$config = $this->config;
$config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client']));
$config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']);
$config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']);
// Replace DS
$config['dir.dest'] = Path::clean($config['dir.dest']);
$config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
$config['dir.src'] = Path::clean($config['dir.src']);
return $this;
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Component\Add;
use GeneratorBundle\Action\Component\Subsystem;
use GeneratorBundle\Controller\Component\AbstractComponentController;
/**
* Class SubsystemController
*
* @since 1.0
*/
class ItemController extends AbstractComponentController
{
/**
* Do Execute.
*
* @return void
*/
protected function doExecute()
{
$this->config['item_name'] = '{{controller.item.name.lower}}';
$this->config['list_name'] = '{{controller.list.name.lower}}';
$this->doAction(new Subsystem\PrepareAction);
$this->doAction(new Subsystem\CopyItemAction);
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Component\Add;
use GeneratorBundle\Action\Component\Subsystem;
use GeneratorBundle\Controller\Component\AbstractComponentController;
/**
* Class SubsystemController
*
* @since 1.0
*/
class ListController extends AbstractComponentController
{
/**
* Do Execute.
*
* @return void
*/
protected function doExecute()
{
$this->config['item_name'] = '{{controller.item.name.lower}}';
$this->config['list_name'] = '{{controller.list.name.lower}}';
$this->doAction(new Subsystem\PrepareAction);
$this->doAction(new Subsystem\CopyListAction);
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Component\Add;
use GeneratorBundle\Action\Component;
use GeneratorBundle\Controller\Component\AbstractComponentController;
/**
* Class SubsystemController
*
* @since 1.0
*/
class SubsystemController extends AbstractComponentController
{
/**
* Do Execute.
*
* @return void
*/
protected function doExecute()
{
$this->config['item_name'] = '{{controller.item.name.lower}}';
$this->config['list_name'] = '{{controller.list.name.lower}}';
$this->doAction(new Component\Subsystem\PrepareAction);
$this->doAction(new Component\Subsystem\CopyItemAction);
$this->doAction(new Component\Subsystem\CopyListAction);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,41 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Component;
use GeneratorBundle\Action;
/**
* Class InitController
*
* @since 1.0
*/
class InitController extends AbstractComponentController
{
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @throws \LogicException
* @throws \RuntimeException
*/
public function doExecute()
{
$this->doAction(new Action\CopyAllAction);
if ($this->config['client'] === 'administrator')
{
$this->doAction(new Action\Component\ImportSqlAction);
$this->doAction(new Action\Component\CopyLanguageAction);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Component\Template;
use GeneratorBundle\Action;
use GeneratorBundle\Controller\Component\AbstractComponentController;
/**
* Class ConvertController
*
* @since 1.0
*/
class ConvertController extends AbstractComponentController
{
/**
* Do Execute.
*
* @return boolean
*/
protected function doExecute()
{
// Flip src and dest because we want to convert template.
$dest = $this->config->get('dir.dest');
$src = $this->config->get('dir.src');
$this->config->set('dir.dest', $src);
$this->config->set('dir.src', $dest);
$this->doAction(new Action\Component\ConvertTemplateAction);
return true;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,263 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller;
use Muse\Controller\AbstractController;
use Muse\Controller\AbstractTaskController;
use Muse\IO\IOInterface;
use GeneratorBundle\Prompter\ElementPrompter;
use GeneratorBundle\Provider\GeneratorBundleProvider;
use GeneratorBundle\Provider\OperatorProvider;
use Windwalker\Registry\Registry;
use Windwalker\DI\Container;
use Windwalker\Console\Command\Command;
/**
* Class GeneratorController
*
* @since 1.0
*/
class GeneratorController extends AbstractController
{
/**
* Property task.
*
* @var string
*/
protected $task = null;
/**
* Property type.
*
* @var string
*/
protected $type = null;
/**
* Property name.
*
* @var string
*/
protected $name = null;
/**
* Property element.
*
* @var string
*/
protected $element = null;
/**
* Property group.
*
* @var string
*/
protected $group = null;
/**
* Property client.
*
* @var string
*/
protected $client = null;
/**
* Property template.
*
* @var string
*/
protected $template = null;
/**
* Property container.
*
* @var Container
*/
protected $container = null;
/**
* Property command.
*
* @var Command
*/
protected $command = null;
/**
* The mapper to find extension type.
*
* @var array
*/
protected $extMapper = array(
'com_' => 'component',
'mod_' => 'module',
'plg_' => 'plugin',
// 'lib_' => 'library',
// 'tpl_' => 'template'
);
/**
* constructor.
*
* @param Command $command
* @param Container $container
* @param IOInterface $io
*/
public function __construct(Command $command, Container $container = null, IOInterface $io = null)
{
$this->command = $command;
$container = $container ? : Container::getInstance();
$this->container = $container;
$container->registerServiceProvider(new GeneratorBundleProvider($command));
$io = $io ? : $container->get('io');
$io->setCommand($command);
parent::__construct($io);
$container->registerServiceProvider(new OperatorProvider($command));
}
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @since 12.1
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
$config = array();
$this->out()->out('Start generating...')->out();
// Prepare basic data.
$command = $this->command;
$element = $command->getArgument(0, new ElementPrompter('Please enter extension element: '));
list($extension, $name, $element, $group) = $this->extractElement($element);
$this->element = $config['element'] = $element;
$this->type = $config['extension'] = $extension;
$this->name = $config['name'] = $name;
$this->group = $config['group'] = $group;
$this->template = $config['template'] = $this->command->getOption('t');
$this->client = $config['client'] = $this->command->getOption('c');
if ($this->client === 'admin')
{
$this->client = $config['client'] = 'administrator';
}
// Get Handler
$task = array_map('ucfirst', explode('.', $this->getTask()));
$task = implode('\\', $task);
$class = 'GeneratorBundle\\Controller\\';
$class .= ucfirst($this->type) . '\\' . $task . 'Controller';
if (!class_exists($class))
{
throw new \RuntimeException(sprintf('Action %s of %s not support.', $this->type, $this->getTask()));
}
/** @var AbstractTaskController $controller */
$controller = new $class($this->container, $this->io, new Registry($config));
$controller->execute();
$this->out()->out('Template generated.');
}
/**
* Extract element.
*
* @param string $element he extension element name, example: com_content or plg_group_name
*
* @return array
*
* @throws \InvalidArgumentException
*/
protected function extractElement($element)
{
$prefix = substr($element, 0, 4);
$ext = $this->getExtType($prefix);
$group = '';
$name = substr($element, 4);
// Get group
if ($ext === 'plugin')
{
$name = explode('_', $name);
$group = array_shift($name);
$name = implode('_', $name);
if (!$name)
{
throw new \InvalidArgumentException(sprintf('Plugin name need group, eg: "plg_group_name", "%s" given.', $element));
}
}
return array($ext, $name, $prefix . $name, $group);
}
/**
* getExtType
*
* @param string $prefix
*
* @return mixed
*
* @throws \InvalidArgumentException
*/
protected function getExtType($prefix)
{
if (empty($this->extMapper[$prefix]))
{
throw new \InvalidArgumentException(sprintf('Invalid extension prefix "%s".', $prefix));
}
return $this->extMapper[$prefix];
}
/**
* getTask
*
* @return string
*/
public function getTask()
{
return $this->task;
}
/**
* setTask
*
* @param string $task
*
* @return GeneratorController Return self to support chaining.
*/
public function setTask($task)
{
$this->task = $task;
return $this;
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Module;
use Muse\IO\IOInterface;
use GeneratorBundle\Controller\AbstractJExtensionController;
use Windwalker\Registry\Registry;
use Windwalker\DI\Container;
/**
* Class AbstractPluginController
*
* @since 1.0
*/
abstract class AbstractModuleController extends AbstractJExtensionController
{
/**
* Constructor.
*
* @param \Windwalker\DI\Container $container
* @param \Muse\IO\IOInterface $io
* @param Registry $config
*/
public function __construct(Container $container, IOInterface $io, Registry $config = null)
{
$config['client'] = $config['client'] ? : 'site';
parent::__construct($container, $io, $config);
$config['replace.module.client'] = 'client="' . $config['client'] . '"';
// Set copy dir.
$config->set('dir.src', $config->get('dir.tmpl'));
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Module;
use GeneratorBundle\Action;
/**
* Class AddController
*
* @since 1.0
*/
class InitController extends AbstractModuleController
{
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @since 1.0
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
$this->doAction(new Action\CopyAllAction);
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Module\Template;
use GeneratorBundle\Action;
use GeneratorBundle\Controller\Module\AbstractModuleController;
/**
* Class ConvertController
*
* @since 1.0
*/
class ConvertController extends AbstractModuleController
{
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @since 1.0
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
// Flip src and dest because we want to convert template.
$dest = $this->config->get('dir.dest');
$src = $this->config->get('dir.src');
$this->config->set('dir.dest', $src);
$this->config->set('dir.src', $dest);
$this->doAction(new Action\ConvertTemplateAction);
$this->doAction(new Action\Module\ReplaceXmlClientAction);
return true;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,45 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Plugin;
use Muse\IO\IOInterface;
use GeneratorBundle\Controller\AbstractJExtensionController;
use Windwalker\Registry\Registry;
use Windwalker\DI\Container;
/**
* Class AbstractPluginController
*
* @since 1.0
*/
abstract class AbstractPluginController extends AbstractJExtensionController
{
/**
* Constructor.
*
* @param \Windwalker\DI\Container $container
* @param \Muse\IO\IOInterface $io
* @param Registry $config
*/
public function __construct(Container $container, IOInterface $io, Registry $config = null)
{
// Reset element back to plg_group_name
$config['element'] = 'plg_' . strtolower($config['group']) . '_' . strtolower($config['name']);
$config['client'] = 'site';
$this->replace['plugin.group.lower'] = strtolower($config['group']);
$this->replace['plugin.group.upper'] = strtoupper($config['group']);
$this->replace['plugin.group.cap'] = ucfirst($config['group']);
parent::__construct($container, $io, $config);
// Set copy dir.
$config->set('dir.src', $config->get('dir.tmpl'));
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Plugin;
use GeneratorBundle\Action;
/**
* Class AddController
*
* @since 1.0
*/
class InitController extends AbstractPluginController
{
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @since 1.0
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
$this->doAction(new Action\CopyAllAction);
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Controller\Plugin\Template;
use GeneratorBundle\Action;
use GeneratorBundle\Controller\Plugin\AbstractPluginController;
/**
* Class ConvertController
*
* @since 1.0
*/
class ConvertController extends AbstractPluginController
{
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @since 1.0
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
// Flip src and dest because we want to convert template.
$dest = $this->config->get('dir.dest');
$src = $this->config->get('dir.src');
$this->config->set('dir.dest', $src);
$this->config->set('dir.src', $dest);
$this->doAction(new Action\ConvertTemplateAction);
return true;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,177 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later;
*/
namespace GeneratorBundle\Controller\Test;
use GeneratorBundle\Action\Test\GenClassAction;
use Muse\Filesystem\Path;
use Windwalker\Registry\Registry;
use Muse\Controller\AbstractTaskController;
use Muse\IO\IOInterface;
use Windwalker\Console\Prompter\ValidatePrompter;
use Windwalker\DI\Container;
use Windwalker\String\SimpleTemplate;
use Windwalker\String\StringHelper;
use Windwalker\String\StringNormalise;
/**
* The GenController class.
*
* @since 2.1
*/
class GenController extends AbstractTaskController
{
/**
* Property container.
*
* @var Container
*/
protected $container;
/**
* Constructor.
*
* @param \Windwalker\DI\Container $container
* @param \Muse\IO\IOInterface $io
* @param Registry $config
*/
public function __construct(Container $container, IOInterface $io, Registry $config = null)
{
// // Set copy dir.
// $config->set('dir.dest', PathHelper::get(strtolower($config['element']), $config['client']));
//
// $config->set('dir.tmpl', GENERATOR_BUNDLE_PATH . '/Template/' . $config['extension'] . '/' . $config['template']);
//
// $config->set('dir.src', $config->get('dir.tmpl') . '/' . $config['client']);
//
// // Replace DS
// $config['dir.dest'] = Path::clean($config['dir.dest']);
//
// $config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
//
// $config['dir.src'] = Path::clean($config['dir.src']);
// Push container
$this->container = $container;
parent::__construct($io, $config);
}
/**
* Execute the controller.
*
* @return boolean True if controller finished execution, false if the controller did not
* finish execution. A controller might return false if some precondition for
* the controller to run has not been satisfied.
*
* @throws \LogicException
* @throws \RuntimeException
*/
public function execute()
{
$package = $this->io->getArgument(0, new ValidatePrompter('Enter package name: '));
$class = $this->io->getArgument(1, new ValidatePrompter('Enter class name: '));
$class = StringNormalise::toClassNamespace($class);
$target = $this->io->getArgument(2, $package . '\\' . $class . 'Test');
$target = StringNormalise::toClassNamespace($target);
$package = ucfirst($package);
if (!class_exists($class))
{
$class = 'Windwalker\\' . $package . '\\' . $class;
}
if (!class_exists($class))
{
$this->out('Class not exists: ' . $class);
exit();
}
$replace = $this->replace;
$ref = new \ReflectionClass($class);
$replace['origin.class.dir'] = dirname($ref->getFileName());
$replace['origin.class.file'] = $ref->getFileName();
$replace['origin.class.name'] = $ref->getName();
$replace['origin.class.shortname'] = $ref->getShortName();
$replace['origin.class.namespace'] = $ref->getNamespaceName();
$replace['test.dir'] = WINDWALKER_ROOT . DIRECTORY_SEPARATOR . 'test';
$replace['test.class.name'] = 'Windwalker\\Test\\' . $target;
$replace['test.class.file'] = Path::clean($replace['test.dir'] . DIRECTORY_SEPARATOR . $target . '.php');
$replace['test.class.dir'] = dirname($replace['test.class.file']);
$replace['test.class.shortname'] = $this->getShortname(StringNormalise::toClassNamespace($replace['test.class.name']));
$replace['test.class.namespace'] = $this->getNamespace($replace['test.class.name']);
$this->replace = $replace;
$config = new Registry;
// Set replace to config.
foreach ($this->replace as $key => $val)
{
$config->set('replace.' . $key, $val);
}
$methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC);
$methodTmpl = file_get_contents(GENERATOR_BUNDLE_PATH . '/Template/test/testMethod.php');
$methodCodes = array();
foreach ($methods as $method)
{
$config['replace.origin.method'] = $method->getName();
$config['replace.test.method'] = ucfirst($method->getName());
$methodCodes[] = SimpleTemplate::render($methodTmpl, $config->get('replace'));
}
$config['replace.test.methods'] = implode("", $methodCodes);
$this->replace = $config->get('replace');
$this->config = $config;
$this->doAction(new GenClassAction);
$this->out('Generate test class: ' . $replace['test.class.name'] . ' to file: ' . $replace['test.class.file'])->out();
return true;
}
/**
* getShortname
*
* @param string $class
*
* @return mixed
*/
protected function getShortname($class)
{
$class = explode('\\', $class);
return array_pop($class);
}
/**
* getNamespace
*
* @param string $class
*
* @return string
*/
protected function getNamespace($class)
{
$class = explode('\\', $class);
array_pop($class);
return implode('\\', $class);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,55 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later;
*/
namespace GeneratorBundle\Controller;
use GeneratorBundle\Controller\Test\GenController;
use Windwalker\Registry\Registry;
use Windwalker\String\StringNormalise;
use Windwalker\Utilities\Reflection\ReflectionHelper;
define('WINDWALKER_ROOT', realpath(JPATH_LIBRARIES . '/windwalker'));
/**
* The TestGeneratorController class.
*
* @since 2.1
*/
class TestGeneratorController extends GeneratorController
{
/**
* Property lastOutput.
*
* @var mixed
*/
protected $lastOutput = null;
/**
* Property lastReturn.
*
* @var mixed
*/
protected $lastReturn = null;
/**
* 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
*/
public function execute()
{
$config = array();
$controller = new GenController($this->container, $this->io, new Registry($config));
return $controller->execute();
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,48 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\FileOperator;
use Windwalker\Filesystem\File;
/**
* Class ConvertOperator
*
* @since 1.0
*/
class ConvertOperator extends CopyOperator
{
/**
* copyFile
*
* @param string $src
* @param string $dest
* @param array $replace
*
* @return void
*/
protected function copyFile($src, $dest, $replace = array())
{
// Replace dest file name.
$dest = strtr($dest, $replace);
if (is_file($dest))
{
$this->io->out('File exists: ' . $dest);
}
else
{
$content = strtr(file_get_contents($src), $replace);
if (File::write($dest, $content))
{
$this->io->out('File created: ' . $dest);
}
}
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\FileOperator;
use Muse\FileOperator\CopyOperator as CodeGeneratorCopyOperator;
use Windwalker\Filesystem\File;
use Windwalker\String\SimpleTemplate;
use Windwalker\String\StringHelper;
/**
* Class CopyOperator
*
* @since 1.0
*/
class CopyOperator extends CodeGeneratorCopyOperator
{
/**
* copyFile
*
* @param string $src
* @param string $dest
* @param array $replace
*
* @return void
*/
protected function copyFile($src, $dest, $replace = array())
{
// Replace dest file name.
$dest = SimpleTemplate::render($dest, $replace);
if (is_file($dest))
{
$this->io->out('File exists: ' . $dest);
}
else
{
$content = SimpleTemplate::render(file_get_contents($src), $replace);
if (File::write($dest, $content))
{
$this->io->out('File created: ' . $dest);
}
}
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,22 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle;
use Windwalker\Bundle\AbstractBundle;
define('GENERATOR_BUNDLE_PATH', __DIR__);
/**
* Class ComponentBuilderBundle
*
* @since 1.0
*/
class GeneratorBundle extends AbstractBundle
{
}

View File

@ -0,0 +1,89 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Prompter;
/**
* Class ElementPrompter
*
* @since 1.0
*/
class ElementPrompter extends NotNullPrompter
{
/**
* Returning message if valid fail.
*
* @var string
*
* @since 1.0
*/
protected $noValidMessage = ' Not valid element name.';
/**
* Returning message if valid fail and close.
*
* @var string
*
* @since 1.0
*/
protected $closeMessage = ' Please enter valid element.';
/**
* The mapper to find extension type.
*
* @var array
*/
protected $extMapper = array(
'com_' => 'component',
'mod_' => 'module',
'plg_' => 'plugin',
// 'lib_' => 'library',
// 'tpl_' => 'template'
);
/**
* Get callable handler.
*
* @return callable The validate callback.
*
* @since 1.0
*/
public function getHandler()
{
$handler = parent::getHandler();
return function($value) use ($handler)
{
if (!call_user_func($handler, $value))
{
return false;
}
$prefix = substr($value, 0, 4);
return $this->validateExtType($prefix);
};
}
/**
* getExtType
*
* @param string $prefix
*
* @return mixed
*/
protected function validateExtType($prefix)
{
if (empty($this->extMapper[$prefix]))
{
return false;
}
return true;
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Prompter;
use Windwalker\Console\Prompter\ValidatePrompter;
/**
* Class NotNullPrompter
*
* @since 1.0
*/
class NotNullPrompter extends ValidatePrompter
{
/**
* Retry times.
*
* @var int
*
* @since 1.0
*/
protected $attempt = 3;
/**
* If this property set to true, application will be closed when validate fail.
*
* @var boolean
*
* @since 1.0
*/
protected $failToClose = true;
/**
* Returning message if valid fail.
*
* @var string
*
* @since 1.0
*/
protected $noValidMessage = ' No value?';
/**
* Returning message if valid fail and close.
*
* @var string
*
* @since 1.0
*/
protected $closeMessage = ' Please enter something.';
/**
* Get callable handler.
*
* @return callable The validate callback.
*
* @since 1.0
*/
public function getHandler()
{
return function($value)
{
return (!is_null($value) && $value !== '');
};
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,58 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Provider;
use Muse\Windwalker\IO;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Windwalker\Console\Command\Command;
/**
* Class GeneratorBundleProvider
*
* @since 1.0
*/
class GeneratorBundleProvider implements ServiceProviderInterface
{
/**
* Property command.
*
* @var Command
*/
protected $command;
/**
* Constructor.
*
* @param Command $command
*/
public function __construct(Command $command)
{
$this->command = $command;
}
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return Container Returns itself to support chaining.
*
* @since 1.0
*/
public function register(Container $container)
{
$ioClass = 'GeneratorBundle\\IO\\IO';
$container->alias('io', $ioClass)
->alias('Muse\\IO\\IO', $ioClass)
->alias('Muse\\IO\\IOInterface', $ioClass)
->share($ioClass, new IO($this->command));
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2016 LYRASOFT, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace GeneratorBundle\Provider;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
/**
* Class OperatorProvider
*
* @since 1.0
*/
class OperatorProvider implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return Container Returns itself to support chaining.
*
* @since 1.0
*/
public function register(Container $container)
{
$container->alias('operator.copy', 'GeneratorBundle\\FileOperator\\CopyOperator')
->buildSharedObject('GeneratorBundle\\FileOperator\\CopyOperator');
$container->alias('operator.convert', 'GeneratorBundle\\FileOperator\\ConvertOperator')
->buildSharedObject('GeneratorBundle\\FileOperator\\ConvertOperator');
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<access component="{{extension.element.lower}}">
<section name="component">
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.options" title="JACTION_OPTIONS" description="JACTION_OPTIONS_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
<action name="core.create" title="JACTION_CREATE" description="JACTION_CREATE_COMPONENT_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="JACTION_EDITOWN_COMPONENT_DESC" />
<action name="core.edit.value" title="JACTION_EDITVALUE" description="JACTION_EDITVALUE_COMPONENT_DESC" />
</section>
<section name="category">
<action name="core.create" title="JACTION_CREATE" description="COM_CATEGORIES_ACCESS_CREATE_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="COM_CATEGORIES_ACCESS_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_CATEGORIES_ACCESS_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="COM_CATEGORIES_ACCESS_EDITOWN_DESC" />
</section>
<section name="{{controller.item.name.lower}}">
<action name="core.delete" title="JACTION_DELETE" description="JACTION_DELETE_COMPONENT_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
</section>
<section name="fieldgroup">
<action name="core.create" title="JACTION_CREATE" description="COM_FIELDS_GROUP_PERMISSION_CREATE_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="COM_FIELDS_GROUP_PERMISSION_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_FIELDS_GROUP_PERMISSION_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_FIELDS_GROUP_PERMISSION_EDITSTATE_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="COM_FIELDS_GROUP_PERMISSION_EDITOWN_DESC" />
<action name="core.edit.value" title="JACTION_EDITVALUE" description="COM_FIELDS_GROUP_PERMISSION_EDITVALUE_DESC" />
</section>
<section name="field">
<action name="core.delete" title="JACTION_DELETE" description="COM_FIELDS_FIELD_PERMISSION_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_FIELDS_FIELD_PERMISSION_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_FIELDS_FIELD_PERMISSION_EDITSTATE_DESC" />
<action name="core.edit.value" title="JACTION_EDITVALUE" description="COM_FIELDS_FIELD_PERMISSION_EDITVALUE_DESC" />
</section>
</access>

View File

@ -0,0 +1,33 @@
/*!
* {{extension.element.lower}}
*
* Copyright 2016 {ORGANIZATION}
* License GNU General Public License version 2 or later.
*/
/* GLOBAL */
/* BODY */
/* TYPO */
/* LAYOUT */
/* CONTENT */
/* FILTER */
/* TABLE */
/* FORM */
/* FOOTER */

View File

@ -0,0 +1,8 @@
/**
* @package Joomla.Administrator
* @subpackage {{extension.element.lower}}
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
var {{extension.name.cap}} = {};

View File

@ -0,0 +1,36 @@
<?php
/**
* Part of Component {{extension.name.cap}} files.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
defined('_JEXEC') or die;
/**
* {{extension.name.cap}} Component
*
* @since 1.0
*/
final class {{extension.name.cap}}Component extends \{{extension.name.cap}}\Component\{{extension.name.cap}}Component
{
/**
* Default task name.
*
* @var string
*/
protected $defaultController = '{{controller.list.name.lower}}.display';
/**
* Prepare hook of this component.
*
* Do some customize initialise through extending this method.
*
* @return void
*/
public function prepare()
{
parent::prepare();
}
}

View File

@ -0,0 +1,9 @@
{
"name" : "smstw/{{extension.name.lower}}",
"require" : {
},
"require-dev" : {
}
}

View File

@ -0,0 +1,247 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<fieldset name="component"
label="{{extension.element.upper}}_COMPONENT_LABEL"
description="{{extension.element.upper}}_COMPONENT_DESC"
addfieldpath="administrator/components/{{extension.element.lower}}/model/field"
>
<field name="{{controller.item.name.lower}}_list"
type="{{controller.item.name.lower}}_list"
default="5"
extension="{{extension.element.lower}}"
view_list="{{controller.list.name.lower}}"
view_item="{{controller.item.name.lower}}"
label="{{extension.element.upper}}_SELECT_{{controller.item.name.upper}}"
description="{{extension.element.upper}}_SELECT_{{controller.item.name.upper}}_DESC"
quickadd="true"
>
<option>JOPTION_DO_NOT_USE</option>
</field>
<field name="{{controller.item.name.lower}}_modal"
type="{{controller.item.name.lower}}_modal"
default="7"
extension="{{extension.element.lower}}"
view_list="{{controller.list.name.lower}}"
view_item="{{controller.item.name.lower}}"
label="{{extension.element.upper}}_SELECT_{{controller.item.name.upper}}"
description="{{extension.element.upper}}_SELECT_{{controller.item.name.upper}}_DESC"
quickadd="true"
/>
<field name="finder"
type="finder"
default=""
handler="{{extension.element.lower}}"
root="images"
start_path=""
label="Finder"
description="{{extension.element.upper}}_SELECT_{{controller.item.name.upper}}_DESC"
preview="true"
onlyimage="true"
/>
<field name="limit"
type="text"
default="20"
label="Number"
/>
</fieldset>
<fieldset name="item">
<field name="link_titles"
type="list"
description="JGLOBAL_LINKED_TITLES_DESC"
label="JGLOBAL_LINKED_TITLES_LABEL"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="link_titles_in_list"
type="list"
description="{{extension.element.upper}}_LINKED_TITLES_IN_LIST_DESC"
label="{{extension.element.upper}}_LINKED_TITLES_IN_LIST"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="show_intro"
type="list"
description="JGLOBAL_SHOW_INTRO_DESC"
label="JGLOBAL_SHOW_INTRO_LABEL"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
<field name="show_noauth"
type="list"
description="JGLOBAL_SHOW_UNAUTH_LINKS_DESC"
label="JGLOBAL_SHOW_UNAUTH_LINKS_LABEL"
default="1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
<fieldset name="category">
<field name="show_category_title"
type="list"
label="JGLOBAL_SHOW_CATEGORY_TITLE"
description="JGLOBAL_SHOW_CATEGORY_TITLE_DESC"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
<field name="show_description"
type="list"
description="JGLOBAL_SHOW_CATEGORY_DESCRIPTION_DESC"
label="JGLOBAL_SHOW_CATEGORY_DESCRIPTION_LABEL"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
<field name="show_description_image"
type="list"
description="JGLOBAL_SHOW_CATEGORY_IMAGE_DESC"
label="JGLOBAL_SHOW_CATEGORY_IMAGE_LABEL"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
<field name="maxLevel"
type="list"
description="JGLOBAL_MAXLEVEL_DESC"
label="JGLOBAL_MAXLEVEL_LABEL"
default="-1"
>
<option value="-1">JALL</option>
<option value="1">J1</option>
<option value="2">J2</option>
<option value="3">J3</option>
<option value="4">J4</option>
<option value="5">J5</option>
</field>
<field type="spacer"
hr="true" />
<field name="num_leading_items"
type="text"
label="{{extension.element.upper}}_NUM_LEADING_ITEMS"
description="{{extension.element.upper}}_NUM_LEADING_ITEMS_DESC"
size="3"
default="1"
/>
<field name="num_intro_items"
type="text"
label="{{extension.element.upper}}_NUM_INTRO_ITEMS"
description="{{extension.element.upper}}_NUM_INTRO_ITEMS_DESC"
size="3"
default="4"
/>
<field name="num_columns"
type="list"
description="JGLOBAL_NUM_COLUMNS_DESC"
label="JGLOBAL_NUM_COLUMNS_LABEL"
default="2"
>
<option value="1">J1</option>
<option value="2">J2</option>
<option value="3">J3</option>
<option value="4">J4</option>
<option value="5">J6</option>
</field>
<field
name="spacer1"
type="spacer"
hr="true"
/>
<field name="orderby"
type="list"
label="{{extension.element.upper}}_FIELD_ORDER"
description="{{extension.element.upper}}_FIELD_ORDER_DESC"
default="{{controller.item.name.lower}}.created"
>
<option value="{{controller.item.name.lower}}.created ">{{extension.element.upper}}_CREATED</option>
<option value="{{controller.item.name.lower}}.publish_up">{{extension.element.upper}}_PUBLISH_UP</option>
<option value="{{controller.item.name.lower}}.publish_down">{{extension.element.upper}}_PUBLISH_DOWN</option>
<option value="{{controller.item.name.lower}}.modified">{{extension.element.upper}}_MODIFIED</option>
<option value="{{controller.item.name.lower}}.title">JGLOBAL_TITLE</option>
<option value="{{controller.item.name.lower}}.ordering">{{extension.element.upper}}_ORDERING</option>
<option value="{{controller.item.name.lower}}.ordering">{{extension.element.upper}}_FIELD_ID</option>
</field>
<field name="order_dir"
type="list"
label="{{extension.element.upper}}_ORDER_DIR"
description="{{extension.element.upper}}_ORDER_DIR_DESCRIPTION"
default="DESC"
>
<option value="ASC">{{extension.element.upper}}_ORDER_DIR_ASC</option>
<option value="DESC">{{extension.element.upper}}_ORDER_DIR_DESC</option>
</field>
<field name="show_pagination"
type="list"
description="JGLOBAL_PAGINATION_DESC"
label="JGLOBAL_PAGINATION_LABEL"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
<option value="2">JGLOBAL_AUTO</option>
</field>
<field name="show_pagination_results"
type="list"
label="JGLOBAL_PAGINATION_RESULTS_LABEL"
description="JGLOBAL_PAGINATION_RESULTS_DESC"
default="1"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
</fieldset>
<fieldset
name="permissions"
label="JCONFIG_PERMISSIONS_LABEL"
description="JCONFIG_PERMISSIONS_DESC"
>
<field
name="rules"
type="rules"
label="JCONFIG_PERMISSIONS_LABEL"
class="inputbox"
validate="rules"
filter="rules"
component="{{extension.element.lower}}"
section="component" />
</fieldset>
</config>

View File

@ -0,0 +1,44 @@
<?php
/**
* Part of Component {{extension.name.cap}} files.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
use Windwalker\Controller\Resolver\ControllerDelegator;
defined('_JEXEC') or die;
/**
* {{extension.name.cap}} {{controller.item.name.cap}} delegator.
*
* @since 1.0
*/
class {{extension.name.cap}}Controller{{controller.item.name.cap}}Delegator extends ControllerDelegator
{
/**
* Register aliases.
*
* @return void
*/
protected function registerAliases()
{
}
/**
* Create Controller.
*
* @param string $class Controller class name.
*
* @return \Windwalker\Controller\Controller Controller instance.
*/
protected function createController($class)
{
$this->config['allow_url_params'] = array(
'type'
);
return parent::createController($class);
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Part of Component {{extension.name.cap}} files.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
use Windwalker\Controller\Resolver\ControllerDelegator;
defined('_JEXEC') or die;
/**
* {{extension.name.cap}} {{controller.list.name.cap}} delegator.
*
* @since 1.0
*/
class {{extension.name.cap}}Controller{{controller.list.name.cap}}Delegator extends ControllerDelegator
{
/**
* Register aliases.
*
* @return void
*/
protected function registerAliases()
{
}
/**
* Create Controller.
*
* @param string $class Controller class name.
*
* @return \Windwalker\Controller\Controller Controller instance.
*/
protected function createController($class)
{
return parent::createController($class);
}
}

View File

@ -0,0 +1,6 @@
{
"system" : {
"debug" : true,
"development" : true
}
}

View File

@ -0,0 +1,223 @@
<?php
/**
* Part of Component {{extension.name.cap}} files.
*
* @copyright Copyright (C) 2016 {ORGANIZATION}. All rights reserved.
* @license GNU General Public License version 2 or later.
*/
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Windwalker\String\StringInflector;
defined('_JEXEC') or die;
include_once JPATH_LIBRARIES . '/windwalker/src/init.php';
/**
* {{extension.name.cap}} helper.
*
* @since 1.0
*/
abstract class {{extension.name.cap}}Helper
{
/**
* Configure the Link bar.
*
* @param string $vName The name of the active view.
*
* @return void
*
* @throws Exception
*/
public static function addSubmenu($vName)
{
$app = Factory::getApplication();
$inflector = StringInflector::getInstance(true);
// Add Category Menu Item
if ($app->isClient('administrator'))
{
JHtmlSidebar::addEntry(
Text::_('JCATEGORY'),
'index.php?option=com_categories&extension={{extension.element.lower}}',
$vName === 'categories'
);
if (ComponentHelper::isEnabled('com_fields'))
{
JHtmlSidebar::addEntry(
Text::_('JGLOBAL_FIELDS'),
'index.php?option=com_fields&context={{extension.element.lower}}.{{controller.item.name.lower}}',
$vName === 'fields.fields'
);
JHtmlSidebar::addEntry(
Text::_('JGLOBAL_FIELD_GROUPS'),
'index.php?option=com_fields&view=groups&context={{extension.element.lower}}.{{controller.item.name.lower}}',
$vName === 'fields.groups'
);
}
}
foreach (new \DirectoryIterator(JPATH_ADMINISTRATOR . '/components/{{extension.element.lower}}/view') as $folder)
{
if ($folder->isDir() && $inflector->isPlural($view = $folder->getBasename()))
{
JHtmlSidebar::addEntry(
Text::sprintf(sprintf('{{extension.element.upper}}_%s_TITLE_LIST', strtoupper($folder))),
'index.php?option={{extension.element.lower}}&view=' . $view,
$vName === $view
);
}
}
$dispatcher = \JEventDispatcher::getInstance();
$dispatcher->trigger('onAfterAddSubmenu', array('{{extension.element.lower}}', $vName));
}
/**
* Adds Count Items for Category Manager.
*
* @param stdClass[] &$items The banner category objects
*
* @return stdClass[]
*
* @throws \RuntimeException
*
* @since 1.0
*/
public static function countItems(&$items)
{
$db = Factory::getDbo();
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true);
$query->select('state, count(*) AS count')
->from($query->quoteName('#__{{extension.name.lower}}_{{controller.list.name.lower}}'))
->where('catid = ' . (int) $item->id)
->group('state');
$db->setQuery($query);
$elements = (array) $db->loadObjectList();
foreach ($elements as $element)
{
switch ($element->state) {
case 0:
$item->count_unpublished = $element->count;
break;
case 1:
$item->count_published = $element->count;
break;
case 2:
$item->count_archived = $element->count;
break;
case -2:
$item->count_trashed = $element->count;
break;
}
}
}
return $items;
}
/**
* Gets a list of the actions that can be performed.
*
* @param string $option Action option.
*
* @return CMSObject
*/
public static function getActions($option = '{{extension.element.lower}}')
{
$user = Factory::getUser();
$result = new CMSObject;
$actions = array(
'core.admin',
'core.options',
'core.manage',
'core.create',
'core.delete',
'core.edit',
'core.edit.state',
'core.edit.own',
'core.edit.value',
);
foreach ($actions as $action)
{
$result->set($action, $user->authorise($action, $option));
}
return $result;
}
/**
* Returns a valid section for articles. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
*
* @return string|null The new section
*
* @since 1.0
*
* @throws Exception
*/
public static function validateSection($section)
{
if (Factory::getApplication()->isClient('site'))
{
// On the front end we need to map some sections
switch ($section)
{
// Map to {{controller.item.name.lower}}
case '{{controller.item.name.lower}}':
case '{{controller.list.name.lower}}':
$section = '{{controller.item.name.lower}}';
break;
default:
$section = null;
}
}
return $section;
}
/**
* Returns valid contexts
*
* @return array
*
* @since 1.0
*/
public static function getContexts()
{
Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);
$contexts = array(
'{{extension.element.lower}}.{{controller.item.name.lower}}' => Text::_('{{extension.element.upper}}_VIEW_{{controller.item.name.upper}}'),
'{{extension.element.lower}}.categories' => Text::_('JCATEGORY'),
// Add more group here...
);
return $contexts;
}
}

Some files were not shown because too many files have changed in this diff Show More