1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) |
6
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
7
|
|
|
* |
8
|
|
|
* Licensed under The MIT License |
9
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
10
|
|
|
* Redistributions of files must retain the above copyright notice. |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
13
|
|
|
* @link http://cakephp.org CakePHP(tm) Project |
14
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
15
|
|
|
*/ |
16
|
|
|
namespace Burzum\CakeServiceLayer\Command; |
17
|
|
|
|
18
|
|
|
use Bake\Command\SimpleBakeCommand; |
19
|
|
|
use Cake\Console\Arguments; |
20
|
|
|
use Cake\Console\ConsoleIo; |
21
|
|
|
use Cake\Core\Configure; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Command class for generating migration snapshot files. |
25
|
|
|
*/ |
26
|
|
|
class BakeServiceCommand extends SimpleBakeCommand |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Task name used in path generation. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $pathFragment = 'Service/'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $_name; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritDoc |
42
|
|
|
*/ |
43
|
|
|
public static function defaultName(): string |
44
|
|
|
{ |
45
|
|
|
return 'bake service'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritDoc |
50
|
|
|
*/ |
51
|
|
|
public function bake(string $name, Arguments $args, ConsoleIo $io): void |
52
|
|
|
{ |
53
|
|
|
$this->_name = $name; |
54
|
|
|
|
55
|
|
|
parent::bake($name, $args, $io); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritDoc |
60
|
|
|
*/ |
61
|
|
|
public function template(): string |
62
|
|
|
{ |
63
|
|
|
return 'Burzum/CakeServiceLayer.Service/service'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritDoc |
68
|
|
|
*/ |
69
|
|
|
public function templateData(Arguments $arguments): array |
70
|
|
|
{ |
71
|
|
|
$name = $this->_name; |
72
|
|
|
$namespace = Configure::read('App.namespace'); |
73
|
|
|
$pluginPath = ''; |
74
|
|
|
if ($this->plugin) { |
75
|
|
|
$namespace = $this->_pluginNamespace($this->plugin); |
76
|
|
|
$pluginPath = $this->plugin . '.'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$namespace .= '\\Service'; |
80
|
|
|
|
81
|
|
|
$namespacePart = null; |
82
|
|
|
if (strpos($name, '/') !== false) { |
83
|
|
|
$parts = explode('/', $name); |
84
|
|
|
$name = array_pop($parts); |
85
|
|
|
$namespacePart = implode('\\', $parts); |
86
|
|
|
} |
87
|
|
|
if ($namespacePart) { |
88
|
|
|
$namespace .= '\\' . $namespacePart; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return [ |
92
|
|
|
'plugin' => $this->plugin, |
93
|
|
|
'pluginPath' => $pluginPath, |
94
|
|
|
'namespace' => $namespace, |
95
|
|
|
'name' => $name, |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritDoc |
101
|
|
|
*/ |
102
|
|
|
public function name(): string |
103
|
|
|
{ |
104
|
|
|
return 'service'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritDoc |
109
|
|
|
*/ |
110
|
|
|
public function fileName(string $name): string |
111
|
|
|
{ |
112
|
|
|
return $name . 'Service.php'; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|