-
Notifications
You must be signed in to change notification settings - Fork 0
/
smith
101 lines (89 loc) · 3.2 KB
/
smith
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
#!/usr/bin/env php
use Symfony\Component\Console\Application;
use Laminas\Db\TableGateway\Feature\GlobalAdapterFeature;
use Laminas\Db\Adapter\Adapter;
use Chopin\LaminasDb\TableGateway\AbstractTableGateway;
use Chopin\Support\Registry;
use Chopin\Support\ModulesLoader;
use Symfony\Component\Console\Output\ConsoleOutput;
use Chopin\Support\SecurityVerify;
if(strpos(__FILE__, 'dev'.DIRECTORY_SEPARATOR.'smith')!== false)
{
chdir(dirname(__DIR__));
}
/**
*
* @var \Composer\Autoload\ClassLoader $autoloader
*/
$autoloader = require 'vendor/autoload.php';
if (! class_exists(ModulesLoader::class)) {
//開發階段通常都會不存在,需要自行引入
require 'modules/chunghsien/chopin-support/src/ModulesLoader.php';
if (is_dir('src/chunghsien')) {
ModulesLoader::registerPsr4($autoloader, 'modules/chunghsien', 'Chopin');
}
}
$supportHelpersConfig = new \Chopin\Support\ConfigProvider();
$helpersFilepath = $supportHelpersConfig()['chopin-support']['helpers'];
if(is_file($helpersFilepath)) {
require $helpersFilepath;
}
ModulesLoader::registerPsr4($autoloader, 'src');
if(strpos(__FILE__, 'smith.dev.phtml') )
{
$output = new ConsoleOutput();
$output->writeln("<error>請使用 smith腳本。<error>");
exit();
}
/**
*
* @var \Laminas\ServiceManager\ServiceManager $container
*/
$container = require 'config/container.php';
Registry::set(\Laminas\ServiceManager\ServiceManager::class, $container);
$tablePrefix = config('db.adapters')[Adapter::class]['prefix'];
if($tablePrefix)
{
AbstractTableGateway::$prefixTable = $tablePrefix;
}
$adapter = $container->get(Adapter::class);
GlobalAdapterFeature::setStaticAdapter($adapter);
if(APP_ENV == 'development' && !SecurityVerify::verify($adapter))
{
SecurityVerify::generate();
}
$application = new Application();
$commands = $container->get('config')['console']['commands'];
foreach ($commands as $namespace => $path) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($iterator as $fileinfo) {
/**
*
* @var \SplFileInfo $fileinfo
*/
if ($fileinfo->isFile()) {
$pathname = str_replace($path . '/', '', $fileinfo->getPathname());
$_namespace = preg_replace('/\\\\$/', '', $namespace);
$_namespaceArr = explode('\\', $_namespace);
$class = str_replace(DIRECTORY_SEPARATOR, '\\', $pathname);
$class = str_replace('.php', '', $class);
if( is_file($class.'.php') ) {
$classArr = explode('/src/', $class);
$class = end($classArr);
$_namespaceTail = end($_namespaceArr);
if(preg_match('/^'.$_namespaceTail.'/', $class)) {
$class = preg_replace('/^'.$_namespaceTail.'\\\\/', '', $class);
}
}
$fullclass = $namespace . $class;
if (class_exists($fullclass)) {
$reflection = new \ReflectionClass($fullclass);
if (! $reflection->isAbstract()) {
$application->add($reflection->newInstance());
}
}
}
}
}
$application->run();