File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ class Command
27
27
use LogTrait;
28
28
use ModelAwareTrait;
29
29
30
+ /**
31
+ * The name of this command. Inflected from the class name.
32
+ *
33
+ * @var string
34
+ */
35
+ protected $ name ;
36
+
30
37
/**
31
38
* Constructor
32
39
*
@@ -37,6 +44,21 @@ public function __construct()
37
44
{
38
45
$ locator = $ this ->getTableLocator () ? : 'Cake\ORM\TableRegistry ' ;
39
46
$ this ->modelFactory ('Table ' , [$ locator , 'get ' ]);
47
+
48
+ if (!$ this ->name ) {
49
+ list (, $ class ) = namespaceSplit (get_class ($ this ));
50
+ $ this ->name = str_replace ('Command ' , '' , $ class );
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Get the command name.
56
+ *
57
+ * @return string
58
+ */
59
+ public function getName ()
60
+ {
61
+ return $ this ->name ;
40
62
}
41
63
42
64
/**
Original file line number Diff line number Diff line change 18
18
use Cake \ORM \Locator \TableLocator ;
19
19
use Cake \ORM \Table ;
20
20
use Cake \TestSuite \TestCase ;
21
-
21
+ use TestApp \ Command \ ExampleCommand ;
22
22
23
23
/**
24
24
* Test case for Console\Command
@@ -48,4 +48,15 @@ public function testConstructorLoadModel()
48
48
$ command ->loadModel ('Comments ' );
49
49
$ this ->assertInstanceOf (Table::class, $ command ->Comments );
50
50
}
51
+
52
+ /**
53
+ * Test name inflection
54
+ *
55
+ * @return void
56
+ */
57
+ public function testNameInflection ()
58
+ {
59
+ $ command = new ExampleCommand ();
60
+ $ this ->assertSame ('Example ' , $ command ->getName ());
61
+ }
51
62
}
You can’t perform that action at this time.
0 commit comments