Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
Command.php
Go to the documentation of this file.
1<?php
3
6
16class Command {
17
18 protected $name;
19
20 protected $description;
21
22 protected $value;
23
24 protected $aliases;
25
26 protected $parameters;
27
28 protected $examples;
29
30 protected $category;
31
32 protected static $customCommands;
33
34 protected static $customAliases;
35
36 public function __construct(string $name = '', string $value = '', string $description = '', array $aliases = [], array $parameters = [], array $examples = [], string $category = 'custom') {
37 $this->name = $name;
38 $this->value = $value;
39 $this->description = $description;
40 $this->aliases = $aliases;
41 $this->parameters = $parameters;
42 $this->examples = $examples;
43 $this->category = $category;
44 }
45
46 public function simpleString() {
47 return "\t" . $this->name . " [" . $this->value . "]\t\t" . $this->description;
48 }
49
50 public function longString() {
51 $dec = "\t";
52 $result = "\n<b>■ " . $this->name . "</b> [" . ConsoleFormatter::colorize($this->value, ConsoleFormatter::YELLOW) . "] =>";
53 $result .= "\n" . $dec . "· " . $this->description;
54 if (\count($this->aliases) > 0) {
55 $result .= "\n" . $dec . "· Aliases :";
57 array_walk($aliases, function (&$alias) {
58 $alias = "<b>" . $alias . "</b>";
59 });
60 $result .= " " . implode(",", $aliases);
61 }
62 if (\count($this->parameters) > 0) {
63 $result .= "\n" . $dec . "· Parameters :";
64 foreach ($this->parameters as $param => $content) {
65 $result .= "\n" . $dec . "\t<b>-" . $param . "</b>";
66 $result .= $content . "\n";
67 }
68 }
69 if (\count($this->examples) > 0) {
70 $result .= "\n" . $dec . "<b>× Samples :</b>";
71 foreach ($this->examples as $desc => $sample) {
72 if (is_string($desc)) {
73 $result .= "\n" . $dec . "\t" . ConsoleFormatter::colorize($desc, ConsoleFormatter::LIGHT_GRAY);
74 }
75 $result .= "\n" . $dec . "\t · " . ConsoleFormatter::colorize($sample, ConsoleFormatter::CYAN);
76 }
77 }
78 return $result;
79 }
80
81 public static function getInfo($cmd) {
82 $commands = self::getCommands();
83 $result = [];
84 if ($cmd != null) {
85 foreach ($commands as $command) {
86 if ($command->getName() == $cmd) {
87 return [
88 [
89 "info" => "Command <b>{$cmd}</b> find by name",
90 "cmd" => $command
91 ]
92 ];
93 } elseif (\array_search($cmd, $command->getAliases()) !== false) {
94 $result[] = [
95 "info" => "Command <b>{$cmd}</b> find by alias",
96 "cmd" => $command
97 ];
98 } elseif (\stripos($command->getDescription(), $cmd) !== false) {
99 $result[] = [
100 "info" => "Command <b>{$cmd}</b> find in description",
101 "cmd" => $command
102 ];
103 } else {
104 $parameters = $command->getParameters();
105 foreach ($parameters as $parameter) {
106 if ($cmd == $parameter->getName()) {
107 $result[] = [
108 "info" => "Command <b>{$cmd}</b> find by the name of a parameter",
109 "cmd" => $command
110 ];
111 }
112 if (\stripos($parameter->getDescription(), $cmd) !== false) {
113 $result[] = [
114 "info" => "Command <b>{$cmd}</b> find in parameter description",
115 "cmd" => $command
116 ];
117 }
118 }
119 }
120 }
121 }
122 return $result;
123 }
124
125 public static function project() {
126 return new Command("project", "projectName", "Creates a new #ubiquity project.", [
127 "new",
128 "create_project"
129 ], [
130 "b" => Parameter::create("dbName", "Sets the database name.", []),
131 "s" => Parameter::create("serverName", "Defines the db server address.", [], "127.0.0.1"),
132 "p" => Parameter::create("port", "Defines the db server port.", [], "3306"),
133 "u" => Parameter::create("user", "Defines the db server user.", [], "root"),
134 "w" => Parameter::create("password", "Defines the db server password.", [], ""),
135 "h" => Parameter::create("themes", "Install themes.", [
136 "semantic",
137 "bootstrap",
138 "foundation"
139 ], ""),
140 "m" => Parameter::create("all-models", "Creates all models from database.", [], ""),
141 "a" => Parameter::create("admin", "Adds UbiquityMyAdmin tool.", [
142 "true",
143 "false"
144 ], "false"),
145 "i" => Parameter::create("siteUrl", "Sets the site base URL.", []),
146 "e" => Parameter::create("rewriteBase", "Sets .htaccess file rewriteBase.", [])
147 ], [
148 'Creates a new project' => 'Ubiquity new blog',
149 'With admin interface' => 'Ubiquity new blog -a',
150 'and models generation' => 'Ubiquity new blog -a -m -b=blogDB'
151 ], 'installation');
152 }
153
154 public static function controller() {
155 return new Command("controller", "controllerName", "Creates a new controller.", [
156 'create_controller',
157 'create:controller',
158 'create-controller',
159 'createController'
160 ], [
161 "v" => Parameter::create("views", "creates an associated view folder and index.html", [
162 "true",
163 "false"
164 ], 'false'),
165 'o' => Parameter::create('domain', 'The domain in which to create the controller.', [], '')
166 ], [
167 'Creates a controller' => 'Ubiquity controller UserController',
168 'with its associated view' => 'Ubiquity controller UserController -v',
169 'Creates a controller in the orga domain' => 'Ubiquity controller OrgaController -o=orga'
170 ], 'controllers');
171 }
172
173 public static function genModel() {
174 return new Command("genModel", "tableName", "Generates a new model from an existing table.", [
175 'gen_model',
176 'gen:model',
177 'gen-model',
178 'genModel'
179 ], [
180 'd' => Parameter::create('database', 'The database connection to use', [], 'default'),
181 'a' => Parameter::create('access', 'The default access to the class members', [], 'private'),
182 'o' => Parameter::create('domain', 'The domain in which to create the model.', [], '')
183 ], [
184 'Ubiquity genModel User',
185 'Ubiquity genModel Author -d=projects',
186 'Ubiquity genModel Author -d=projects -a=protected'
187 ], 'models');
188 }
189
190 public static function model() {
191 return new Command("model", "modelName", "Generates models from scratch.", [
192 'create_model',
193 'create:model',
194 'create-model',
195 'createModel',
196 'new_model',
197 'new:model',
198 'new-model',
199 'newModel'
200 ], [
201 'd' => Parameter::create('database', 'The database connection to use', [], 'default'),
202 'o' => Parameter::create('domain', 'The domain in which to create the model.', [], ''),
203 'k' => Parameter::create('autoincPk', 'The default primary key defined as autoinc.', [], 'id')
204 ], [
205 'Ubiquity model User',
206 'Ubiquity model Author -d=projects',
207 'Ubiquity model Group,User -o=orga'
208 ], 'models');
209 }
210
211 public static function routes() {
212 return new Command("info-routes", "", "Display the cached routes.", [
213 'info:r',
214 'info_routes',
215 'info:routes',
216 'infoRoutes'
217 ], [
218 "t" => Parameter::create("type", "Defines the type of routes to display.", [
219 "all",
220 "routes",
221 "rest"
222 ]),
223 "l" => Parameter::create("limit", " Specifies the number of routes to return.", []),
224 "o" => Parameter::create("offset", "Specifies the number of routes to skip before starting to return.", []),
225 "s" => Parameter::create("search", "Search routes corresponding to a path.", []),
226 "m" => Parameter::create("method", "Allows to specify a method with search attribute.", [
227 'get',
228 'post',
229 'put',
230 'delete',
231 'patch'
232 ])
233 ], [
234 'All routes' => 'Ubiquity info:routes',
235 'Rest routes' => 'Ubiquity info:routes -type=rest',
236 'Only the routes with the method post' => 'Ubiquity info:routes -type=rest -m=-post'
237 ], 'router');
238 }
239
240 public static function version() {
241 return new Command("version", "", "Return PHP, Framework and dev-tools versions.", [], [], [], 'system');
242 }
243
244 public static function allModels() {
245 return new Command("all-models", "", "Generates all models from database.", [
246 'create-all-models',
247 'all_models',
248 'all:models',
249 'allModels'
250 ], [
251 'd' => Parameter::create('database', 'The database connection to use (offset)', [], 'default'),
252 'a' => Parameter::create('access', 'The default access to the class members', [], 'private'),
253 'o' => Parameter::create('domain', 'The domain in which to create the models.', [], '')
254 ], [
255 'Ubiquity all-models',
256 'Ubiquity all-models -d=projects',
257 'Ubiquity all-models -d=projects -a=protected'
258 ], 'models');
259 }
260
261 public static function clearCache() {
262 return new Command("clear-cache", "", "Clear models cache.", [
263 'clear_cache',
264 'clear:cache',
265 'clearCache'
266 ], [
267 "t" => Parameter::create("type", "Defines the type of cache to reset.", [
268 "all",
269 "annotations",
270 "controllers",
271 "rest",
272 "models",
273 "queries",
274 "views"
275 ], 'all')
276 ], [
277 'Clear all caches' => 'Ubiquity clear-cache -t=all',
278 'Clear models cache' => 'Ubiquity clear-cache -t=models'
279 ], 'cache');
280 }
281
282 public static function initCache() {
283 return new Command("init-cache", "", "Init the cache for models, router, rest.", [
284 'init_cache',
285 'init:cache',
286 'initCache'
287 ], [
288 "t" => Parameter::create("type", "Defines the type of cache to create.", [
289 "all",
290 "controllers",
291 "acls",
292 "rest",
293 "models"
294 ], 'all')
295 ], [
296 'Init all caches' => 'Ubiquity init-cache',
297 'Init models cache' => 'Ubiquity init-cache -t=models'
298 ], 'cache');
299 }
300
301 public static function serve() {
302 return new Command("serve", "", "Start a web server.", [], [
303 "h" => Parameter::create("host", "Sets the host ip address.", [], '127.0.0.1'),
304 "p" => Parameter::create("port", "Sets the listen port number.", [], 8090),
305 "n" => Parameter::create("nolr", "Starts without live-reload.", [], false),
306 "l" => Parameter::create("lrport", "Sets the live-reload listen port number.", [], '35729'),
307 "t" => Parameter::create("type", "Sets the server type.", [
308 'php',
309 'react',
310 'swoole',
311 'roadrunner'
312 ], 'php')
313 ], [
314 'Starts a php server at 127.0.0.1:8090' => 'Ubiquity serve',
315 'Starts a reactPHP server at 127.0.0.1:8080' => 'Ubiquity serve -t=react'
316 ], 'servers');
317 }
318
319 public static function liveReload() {
320 return new Command("livereload", "path", "Start the live reload server.", [
321 'live-reload',
322 'live'
323 ], [
324 "p" => Parameter::create("port", "Sets the listen port number.", [], 35729),
325 "e" => Parameter::create("exts", "Specify extentions to observe .", [], 'php,html'),
326 "x" => Parameter::create("exclusions", "Exclude file matching pattern .", [], 'cache/,logs/')
327 ], [
328 'Starts the live-reload server at 127.0.0.1:35729' => 'Ubiquity live-reload',
329 'Starts the live-reload server at 127.0.0.1:35800 excluding logs directory' => 'Ubiquity live-reload -p=35800 -x=logs/'
330 ], 'servers');
331 }
332
333 public static function selfUpdate() {
334 return new Command("self-update", "", "Updates Ubiquity framework for the current project.", [], [], [], 'installation');
335 }
336
337 public static function admin() {
338 return new Command("admin", "", "Add UbiquityMyAdmin webtools to the current project.", [], [], [], 'installation');
339 }
340
341 public static function help() {
342 return new Command("help", "?", "Get some help about a dev-tools command.", [], [], [
343 'Get some help about crud' => 'Ubiquity help crud'
344 ], 'system');
345 }
346
347 public static function crudController() {
348 return new Command("crud", "crudControllerName", "Creates a new CRUD controller.", [
349 'crud_controller',
350 'crud:controller',
351 'crud-controller',
352 'crudController'
353 ], [
354 "r" => Parameter::create("resource", "The model used", []),
355 "d" => Parameter::create("datas", "The associated Datas class", [
356 "true",
357 "false"
358 ], "true"),
359 "v" => Parameter::create("viewer", "The associated Viewer class", [
360 "true",
361 "false"
362 ], "true"),
363 "e" => Parameter::create("events", "The associated Events class", [
364 "true",
365 "false"
366 ], "true"),
367 "t" => Parameter::create("templates", "The templates to modify", [
368 "index",
369 "form",
370 "display"
371 ], "index,form,display"),
372 "p" => Parameter::create("path", "The associated route", []),
373 'o' => Parameter::create('domain', 'The domain in which to create the controller.', [], '')
374 ], [
375 'Creates a crud controller for the class models\User' => 'Ubiquity crud CrudUsers -r=User',
376 'and associates a route to it' => 'Ubiquity crud CrudUsers -r=User -p=/users',
377 'allows customization of index and form templates' => 'Ubiquity crud CrudUsers -r=User -t=index,form',
378 'Creates a crud controller for the class models\projects\Author' => 'Ubiquity crud Authors -r=models\projects\Author'
379 ], 'controllers');
380 }
381
382 public static function indexCrudController() {
383 return new Command("crud-index", "crudControllerName", "Creates a new index-CRUD controller.", [
384 'crud-index-controller',
385 'crud_index',
386 'crud:index',
387 'crudIndex'
388 ], [
389 "d" => Parameter::create("datas", "The associated Datas class", [
390 "true",
391 "false"
392 ], "true"),
393 "v" => Parameter::create("viewer", "The associated Viewer class", [
394 "true",
395 "false"
396 ], "true"),
397 "e" => Parameter::create("events", "The associated Events class", [
398 "true",
399 "false"
400 ], "true"),
401 "t" => Parameter::create("templates", "The templates to modify", [
402 "index",
403 "form",
404 "display",
405 "item",
406 "itemHome"
407 ], "index,form,display,home,itemHome"),
408 "p" => Parameter::create("path", "The associated route", [], '{resource}'),
409 'o' => Parameter::create('domain', 'The domain in which to create the controller.', [], '')
410 ], [
411 'Creates an index crud controller' => 'Ubiquity crud-index MainCrud -p=crud/{resource}',
412 'allows customization of index and form templates' => 'Ubiquity index-crud MainCrud -t=index,form'
413 ], 'controllers');
414 }
415
416 public static function restController() {
417 return new Command("rest", "restControllerName", "Creates a new REST controller.", [
418 'rest-controller',
419 'rest:controller',
420 'rest_controller',
421 'restController'
422 ], [
423 "r" => Parameter::create("resource", "The model used", []),
424 "p" => Parameter::create("path", "The associated route", []),
425 'o' => Parameter::create('domain', 'The domain in which to create the controller.', [], '')
426 ], [
427 'Creates a REST controller for the class models\User' => 'Ubiquity rest RestUsers -r=User -p=/rest/users'
428 ], 'rest');
429 }
430
431 public static function restApiController() {
432 return new Command("restapi", "restControllerName", "Creates a new REST API controller.", [
433 'restapi-controller',
434 'restapi:controller',
435 'restapi_controller',
436 'restapiController'
437 ], [
438 "p" => Parameter::create("path", "The associated route", []),
439 'o' => Parameter::create('domain', 'The domain in which to create the controller.', [], '')
440 ], [
441 'Creates a REST API controller' => 'Ubiquity restapi -p=/rest'
442 ], 'rest');
443 }
444
445 public static function dao() {
446 return new Command("dao", "command", "Executes a DAO command (getAll,getOne,count,uGetAll,uGetOne,uCount).", [
447 "DAO"
448 ], [
449 "r" => Parameter::create("resource", "The model used", []),
450 "c" => Parameter::create("condition", "The where part of the query", []),
451 "i" => Parameter::create("included", "The associated members to load (boolean or array: client.*,commands)", []),
452 "p" => Parameter::create("parameters", "The parameters for a parameterized query", []),
453 "f" => Parameter::create("fields", "The fields to display in the response", []),
454 'o' => Parameter::create('domain', 'The domain in which the models are.', [], '')
455 ], [
456 'Returns all instances of models\User' => 'Ubiquity dao getAll -r=User',
457 'Returns all instances of models\User and includes their commands' => 'Ubiquity dao getAll -r=User -i=commands',
458 'Returns the User with the id 5' => 'Ubiquity dao getOne -c="id=5"-r=User',
459 'Returns the list of users belonging to the "Brittany" or "Normandy" regions' => 'Ubiquity uGetAll -r=User -c="region.name= ? or region.name= ?" -p=Brittany,Normandy'
460 ], 'models');
461 }
462
463 public static function authController() {
464 return new Command("auth", "authControllerName", "Creates a new controller for authentification.", [
465 'auth-controller',
466 'auth_controller',
467 'auth:controller',
468 'authController'
469 ], [
470 "e" => Parameter::create("extends", "The base class of the controller (must derived from AuthController)", [], "Ubiquity\\controllers\\auth\\AuthController"),
471 "t" => Parameter::create("templates", "The templates to modify", [
472 "index",
473 "info",
474 "noAccess",
475 "disconnected",
476 "message",
477 "baseTemplate"
478 ], 'index,info,noAccess,disconnected,message,baseTemplate'),
479 "p" => Parameter::create("path", "The associated route", []),
480 'o' => Parameter::create('domain', 'The domain in which to create the controller.', [], '')
481 ], [
482 'Creates a new controller for authentification' => 'Ubiquity auth AdminAuthController',
483 'and associates a route to it' => 'Ubiquity auth AdminAuthController -p=/admin/auth',
484 'allows customization of index and info templates' => 'Ubiquity auth AdminAuthController -t=index,info'
485 ], 'controllers');
486 }
487
488 public static function newAction() {
489 return new Command("action", "controller.action", "Creates a new action in a controller.", [
490 'new-action',
491 'new_action',
492 'new:action',
493 'newAction'
494 ], [
495 "p" => Parameter::create("params", "The action parameters (or arguments)", []),
496 "r" => Parameter::create("route", "The associated route path", []),
497 "v" => Parameter::create("create-view", "Creates the associated view", [
498 "true",
499 "false"
500 ], "false"),
501 'o' => Parameter::create('domain', 'The domain in which the controller is.', [], '')
502 ], [
503 'Adds the action all in controller Users' => 'Ubiquity action Users.all',
504 'Adds the action display in controller Users with a parameter' => 'Ubiquity action Users.display -p=idUser',
505 'and associates a route to it' => 'Ubiquity action Users.display -p=idUser -r=/users/display/{idUser}',
506 'with multiple parameters' => 'Ubiquity action Users.search -p=name,address',
507 'and create the associated view' => 'Ubiquity action Users.search -p=name,address -v'
508 ], 'controllers');
509 }
510
511 public static function newDomain() {
512 return new Command('domain', 'name', 'Creates a new domain (for a Domain Driven Design approach).', [
513 'new-domain',
514 'new_domain',
515 'new:domain',
516 'newDomain'
517 ], [
518 "b" => Parameter::create("base", "The base folder for domains.", [], 'domains')
519 ], [
520 'Creates a new domain users' => 'Ubiquity domain users'
521 ], 'controllers');
522 }
523
524 public static function infoModel() {
525 return new Command("info-model", "?infoType", "Returns the model meta datas.", [
526 'info_model',
527 'info:model',
528 'infoModel'
529 ], [
530 "s" => Parameter::create("separate", "If true, returns each info in a separate table", [
531 "true",
532 "false"
533 ], "false"),
534 "m" => Parameter::create("model", "The model on which the information is sought.", []),
535 "f" => Parameter::create("fields", "The fields to display in the table.", []),
536 'o' => Parameter::create('domain', 'The domain in which the models is.', [], '')
537 ], [
538 'Gets metadatas for User class' => 'Ubiquity info:model -m=User'
539 ], 'models');
540 }
541
542 public static function infoModels() {
543 return new Command('info-models', '', 'Returns the models meta datas.', [
544 'info_models',
545 'info:models',
546 'infoModels'
547 ], [
548 'd' => Parameter::create('database', 'The database connection to use (offset)', [], 'default'),
549 "m" => Parameter::create("models", "The models on which the information is sought.", []),
550 "f" => Parameter::create("fields", "The fields to display in the table.", []),
551 'o' => Parameter::create('domain', 'The domain in which the models are.', [], '')
552 ], [
553 'Gets metadatas for all models in default db' => 'Ubiquity info:models',
554 'Gets metadatas for all models in messagerie db' => 'Ubiquity info:models -d=messagerie',
555 'Gets metadatas for User and Group models' => 'Ubiquity info:models -m=User,Group',
556 'Gets all primary keys for all models' => 'Ubiquity info:models -f=#primaryKeys'
557 ], 'models');
558 }
559
560 public static function infoValidation() {
561 return new Command("info-validation", "?memberName", "Returns the models validation info.", [
562 'info_validation',
563 'info:validation',
564 'infoValidation',
565 'info_validators',
566 'info-validators',
567 'info:validators',
568 'infoValidators'
569 ], [
570 "s" => Parameter::create("separate", "If true, returns each info in a separate table", [
571 'true',
572 'false'
573 ], 'false'),
574 "m" => Parameter::create("model", "The model on which the information is sought.", []),
575 'o' => Parameter::create('domain', 'The domain in which the models is.', [], '')
576 ], [
577 'Gets validators for User class' => 'Ubiquity info:validation -m=User',
578 'Gets validators for User class on member firstname' => 'Ubiquity info:validation firstname -m=User'
579 ], 'models');
580 }
581
582 public static function configInfo() {
583 return new Command("config", "", "Returns the config informations from app/config/config.php.", [
584 'info_config',
585 'info-config',
586 'info:config',
587 'infoConfig'
588 ], [
589 "f" => Parameter::create("fields", "The fields to display.", [])
590 ], [
591 'Display all config vars' => 'Ubiquity config',
592 'Display database config vars' => 'Ubiquity config -f=database'
593 ], 'system');
594 }
595
596 public static function configSet() {
597 return new Command("config-set", "", "Modify/add variables and save them in app/config/config.php. Supports only long parameters with --.", [
598 'set_config',
599 'set-config',
600 'set:config',
601 'setConfig'
602 ], [], [
603 'Assigns a new value to siteURL' => 'Ubiquity config:set --siteURL=http://127.0.0.1/quick-start/',
604 'Change the database name and port' => 'Ubiquity config:set --database.dbName=blog --database.port=3307'
605 ], 'system');
606 }
607
608 public static function newTheme() {
609 return new Command("create-theme", "themeName", "Creates a new theme or installs an existing one.", [
610 'create_theme',
611 'create:theme',
612 'createTheme'
613 ], [
614 "x" => Parameter::create("extend", "If specified, inherits from an existing theme (bootstrap,semantic or foundation).", [
615 'bootstrap',
616 'semantic',
617 'foundation'
618 ]),
619 'o' => Parameter::create('domain', 'The domain in which to create the theme.', [], '')
620 ], [
621 'Creates a new theme custom' => 'Ubiquity create-theme custom',
622 'Creates a new theme inheriting from Bootstrap' => 'Ubiquity theme myBootstrap -x=bootstrap'
623 ], 'gui');
624 }
625
626 public static function installTheme() {
627 return new Command("theme", "themeName", "Installs an existing theme or creates a new one if the specified theme does not exists.", [
628 'install_theme',
629 'install-theme',
630 'install:theme',
631 'installTheme'
632 ], [
633 'o' => Parameter::create('domain', 'The domain in which to install the theme.', [], '')
634 ], [
635 'Creates a new theme custom' => 'Ubiquity theme custom',
636 'Install bootstrap theme' => 'Ubiquity theme bootstrap'
637 ], 'gui');
638 }
639
640 public static function bootstrap() {
641 return new Command("bootstrap", "command", "Executes a command created in app/config/_bootstrap.php file for bootstraping the app.", [
642 "boot"
643 ], [], [
644 'Bootstrap for dev mode' => 'Ubiquity bootstrap dev',
645 'Bootstrap for prod mode' => 'Ubiquity bootstrap prod'
646 ], 'servers');
647 }
648
649 public static function composer() {
650 return new Command("composer", "command", "Executes a composer command.", [
651 "compo"
652 ], [], [
653 'composer update' => 'Ubiquity composer update',
654 'composer update with no-dev' => 'Ubiquity composer nodev',
655 'composer optimization for production' => 'Ubiquity composer optimize'
656 ], 'system');
657 }
658
659 public static function mailer() {
660 return new Command("mailer", "part", "Displays mailer classes, mailer queue or mailer dequeue.", [], [], [
661 'Display mailer classes' => 'Ubiquity mailer classes',
662 'Display mailer messages in queue(To send)' => 'Ubiquity mailer queue',
663 'Display mailer messages in dequeue(sent)' => 'Ubiquity mailer dequeue'
664 ], 'mailer');
665 }
666
667 public static function sendMails() {
668 return new Command("send-mail", "", "Send message(s) from queue.", [
669 'send-mails',
670 'send_mails',
671 'send:mails',
672 'sendMails'
673 ], [
674 "n" => Parameter::create("num", "If specified, Send the mail at the position n in queue.", [])
675 ], [
676 'Send all messages to send from queue' => 'Ubiquity semdMails',
677 'Send the first message in queue' => 'Ubiquity sendMail 1'
678 ], 'mailer');
679 }
680
681 public static function newMail() {
682 return new Command("new-mail", "name", "Creates a new mailer class.", [
683 'new_mail',
684 'new:mail',
685 'newMail'
686 ], [
687 "p" => Parameter::create("parent", "The class parent.", [], '\\Ubiquity\\mailer\\AbstractMail'),
688 "v" => Parameter::create("view", "Add the associated view.", [], false)
689 ], [
690 'Creates a new mailer class' => 'Ubiquity newMail InformationMail'
691 ], 'mailer');
692 }
693
694 public static function newClass() {
695 return new Command('new-class', "name", "Creates a new class.", [
696 'new_class',
697 'new:class',
698 'newClass',
699 'class'
700 ], [
701 "p" => Parameter::create("parent", "The class parent.", [])
702 ], [
703 'Creates a new class' => 'Ubiquity class services.OrgaRepository'
704 ], 'controllers');
705 }
706
707 public static function createCommand() {
708 return new Command("create-command", "commandName", "Creates a new custom command for the devtools.", [
709 'create_command',
710 'create:command',
711 'createCommand'
712 ], [
713 "v" => Parameter::create("value", "The command value (first parameter).", []),
714 "p" => Parameter::create("parameters", "The command parameters (comma separated).", []),
715 "d" => Parameter::create("description", "The command description.", []),
716 "a" => Parameter::create("aliases", "The command aliases (comma separated).", [])
717 ], [
718 'Creates a new custom command' => 'Ubiquity create-command custom'
719 ], 'system');
720 }
721
722 public static function initAcls() {
723 return new Command('acl-init', '', 'Initialize Acls defined with annotations in controllers.', [
724 'acl_init',
725 'acl:init',
726 'aclInit'
727 ], [
728 "m" => Parameter::create("models", "Generates ACL models", []),
729 "p" => Parameter::create("providers", "The providers to use (comma separated).", ['dao'], 'dao'),
730 "d" => Parameter::create("database", "The database offset.", [], 'default'),
731 ], [
732 'Initialize Acls' => 'Ubiquity aclInit',
733 'Initialize Acls and create tables for AclDAOProvider' => 'Ubiquity aclInit -p=dao',
734 'Initialize Acls, create tables for acls db offset and models for AclDAOProvider' => 'Ubiquity aclInit -p=dao -m -d=acls',
735 ], 'security');
736 }
737
738 public static function displayAcls() {
739 return new Command('acl-display', '', 'Display Acls defined with annotations in controllers.', [
740 'acl_display',
741 'acl:display',
742 'aclDisplay'
743 ], [
744 "v" => Parameter::create("value", "The ACL part to display.", [
745 'all',
746 'role',
747 'resource',
748 'permission',
749 'map',
750 'acl'
751 ], 'acl')
752 ], [
753 'Display all defined roles with ACL annotations' => 'Ubiquity aclDisplay role'
754 ], 'security');
755 }
756
757 public static function newEncryptionKey() {
758 return new Command('new-key', 'cypher', 'Generate a new encryption key using a cipher.', [
759 'new_key',
760 'new:key',
761 'newKey'
762 ], [], [
763 'Generate a key for AES-128' => 'Ubiquity new-key 128'
764 ], 'security');
765 }
766
767 public static function infoMigrations() {
768 return new Command("info-migrations", "", "Returns the migration infos.", [
769 'info_migrations',
770 'info:migrations',
771 'infoMigrations'
772 ], [
773 "d" => Parameter::create("database", "The database offset.", [], 'default'),
774 'o' => Parameter::create('domain', 'The domain in which the database models are.', [], '')
775 ], [
776 'Display all migrations for the default database' => 'Ubiquity info:migrations'
777 ], 'models');
778 }
779
780 public static function migrations() {
781 return new Command("migrations", "", "Display and execute the database migrations.", [
782 'migrations',
783 'migrate'
784 ], [
785 "d" => Parameter::create("database", "The database offset.", [], 'default'),
786 'o' => Parameter::create('domain', 'The domain in which the database models are.', [], '')
787 ], [
788 'Display and execute all migrations for the default database' => 'Ubiquity migrations'
789 ], 'models');
790 }
791
792 public static function templateParser(){
793 return new Command("template-parse", "", "Parse a twig template to another template engine.", [
794 'template_parse',
795 'template:parse',
796 'template-parse'
797 ], [
798 "e" => Parameter::create("engine", "The destination template engine.", ['twig','latte','plates'], 'latte'),
799 "d" => Parameter::create("destination", "The destination folder.", [], 'default view folder'),
800 'o' => Parameter::create('origin', 'The folder where the templates are located.', [], 'default view folder')
801 ], [
802 'Migrate all templates in view folder to Latte template engine' => 'Ubiquity template-parse'
803 ], 'views');
804 }
805
806 protected static function getCustomCommandInfos() {
807 $result = [];
808 $commands = self::getCustomCommands();
809 if (is_array($commands)) {
810 foreach ($commands as $o) {
811 $result[] = $o->getCommand();
812 }
813 }
814 return $result;
815 }
816
817 public static function getCustomCommands() {
818 if (\class_exists(\Ubiquity\utils\base\UIntrospection::class)) {
819 if (! isset(self::$customCommands)) {
820 $classes = UIntrospection::getChildClasses('\\Ubiquity\\devtools\\cmd\\commands\\AbstractCustomCommand');
821 foreach ($classes as $class) {
822 $o = new $class();
823 $cmd = $o->getCommand();
824 self::$customCommands[$cmd->getName()] = $o;
825 $aliases = $cmd->getAliases();
826 if (is_array($aliases)) {
827 foreach ($aliases as $alias) {
828 self::$customAliases[$alias] = $o;
829 }
830 }
831 }
832 }
833 }
835 }
836
837 public static function reloadCustomCommands(array $config = []) {
838 if (\class_exists(\Ubiquity\utils\base\UIntrospection::class)) {
839 self::$customCommands = null;
840 self::$customAliases = [];
843 }
844 }
845
846 public static function getCustomAliases() {
848 }
849
850 public static function preloadCustomCommands(array $config = []) {
851 if (\class_exists(\Ubiquity\utils\base\UIntrospection::class)) {
852 $config['cmd-pattern'] ??= 'commands' . \DS . '*.cmd.php';
853 $files = UFileSystem::glob_recursive($config['cmd-pattern']);
854 foreach ($files as $file) {
855 include_once $file;
856 }
857 }
858 }
859
860 public static function getCommandNames(array $excludedCategories = [
861 'installation' => false,
862 'servers' => false
863 ], $excludedCommands = []) {
864 $result = [];
865 $commands = self::getCommands();
866 foreach ($commands as $command) {
867 $cat = $command->getCategory();
868 $commandName = $command->getName();
869 if (! isset($excludedCommands[$commandName]) && ! isset($excludedCategories[$cat])) {
870 $result[] = $commandName;
871 }
872 }
873 return $result;
874 }
875
924
929 public function getName() {
930 return $this->name;
931 }
932
937 public function getDescription() {
938 return $this->description;
939 }
940
945 public function getValue() {
946 if ($this->value != null) {
947 return \ltrim($this->value, '?');
948 }
949 return $this->value;
950 }
951
952 public function hasRequiredValue() {
953 return $this->value != null && \substr($this->value, 0, 1) !== '?';
954 }
955
960 public function getAliases() {
961 return $this->aliases;
962 }
963
968 public function getParameters() {
969 return $this->parameters;
970 }
971
976 public function getExamples() {
977 return $this->examples;
978 }
979
984 public function getCategory() {
985 return $this->category;
986 }
987
992 public function setCategory($category) {
993 $this->category = $category;
994 }
995
996 public function hasParameters() {
997 return \count($this->parameters) > 0;
998 }
999
1000 public function hasValue() {
1001 return $this->value != null;
1002 }
1003
1004 public function isImmediate() {
1005 return ! $this->hasParameters() && ! $this->hasValue();
1006 }
1007
1008 public function __toString() {
1009 return $this->name;
1010 }
1011}
Define a command complete desciption.
Definition Command.php:16
static getCommandNames(array $excludedCategories=['installation'=> false, 'servers'=> false], $excludedCommands=[])
Definition Command.php:860
static preloadCustomCommands(array $config=[])
Definition Command.php:850
__construct(string $name='', string $value='', string $description='', array $aliases=[], array $parameters=[], array $examples=[], string $category='custom')
Definition Command.php:36
static reloadCustomCommands(array $config=[])
Definition Command.php:837
static colorize($string, $color=null, $bgColor=null)
Returns a colored string.
static create(string $name, string $description, array $values, string $defaultValue="")
Return a new parameter.
Definition Parameter.php:92
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
static glob_recursive($pattern, $flags=0)
Find recursively pathnames matching a pattern.
Ubiquity\utils\base$UIntrospection This class is part of Ubiquity.
Class Configuration \config.