Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit efa0eb4

Browse files
committed
use Str to format service and feature names
1 parent 156b939 commit efa0eb4

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

src/Commands/FeatureMakeCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Lucid\Console\Commands;
1313

14+
use Lucid\Console\Str;
1415
use Lucid\Console\Finder;
1516
use Lucid\Console\Filesystem;
1617
use Illuminate\Console\GeneratorCommand;
@@ -114,6 +115,6 @@ protected function getStub()
114115
*/
115116
protected function parseName($name)
116117
{
117-
return studly_case(preg_replace('/Feature(\.php)?$/', '', $name).'Feature');
118+
return Str::feature($name);
118119
}
119120
}

src/Commands/FeaturesListCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ class FeaturesListCommand extends Command
3434
*
3535
* @var string
3636
*/
37-
protected $description = 'List the services in this project.';
37+
protected $description = 'List the features.';
3838

39+
/**
40+
* Execute the console command.
41+
*
42+
* @return bool|null
43+
*/
3944
public function fire()
4045
{
4146
foreach ($this->listFeatures($this->argument('service')) as $service => $features) {

src/Commands/ServiceMakeCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Lucid\Console\Commands;
1313

14+
use Lucid\Console\Str;
1415
use Lucid\Console\Finder;
1516
use Lucid\Console\Filesystem;
1617
use Illuminate\Console\GeneratorCommand;
@@ -93,7 +94,7 @@ protected function getStub()
9394
*/
9495
public function fire()
9596
{
96-
$name = studly_case($this->getNameInput());
97+
$name = Str::service($this->getNameInput());
9798

9899
$slug = snake_case($name);
99100

src/Str.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,43 @@ class Str
2222
* i.e. the name: "CreateArticleFeature.php" with pattern '/Feature.php'
2323
* will result in "Create Article"
2424
*
25-
* @param [type] $name [description]
26-
* @param string $pattern [description]
27-
* @return [type] [description]
25+
* @param string $name
26+
* @param string $pattern
27+
*
28+
* @return string
2829
*/
2930
public static function realName($name, $pattern = '//')
3031
{
3132
$name = preg_replace($pattern, '', $name);
3233

3334
return implode(' ', preg_split('/(?=[A-Z])/', $name, -1, PREG_SPLIT_NO_EMPTY));
3435
}
36+
37+
/**
38+
* Get the given name formatted as a feature.
39+
*
40+
* i.e. "Create Post Feature", "CreatePostFeature.php", "createPost", "createe"
41+
* and many other forms will be transformed to "CreatePostFeature" which is
42+
* the standard feature class name.
43+
*
44+
* @param string $name
45+
*
46+
* @return string
47+
*/
48+
public static function feature($name)
49+
{
50+
return studly_case(preg_replace('/Feature(\.php)?$/', '', $name).'Feature');
51+
}
52+
53+
/**
54+
* Get the given name formatted as a service name.
55+
*
56+
* @param string $name
57+
*
58+
* @return string
59+
*/
60+
public static function service($name)
61+
{
62+
return studly_case($name);
63+
}
3564
}

0 commit comments

Comments
 (0)