Skip to content

Commit 4ae3dc8

Browse files
author
rotimi
committed
Tweaked autoloading of icanboogie/inflector
1 parent 328a8ba commit 4ae3dc8

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

bin/generate-leanorm-classes.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
error_reporting(E_ALL);
44

55
$autoload = false;
6+
$inflectorHelper = false;
67
$files = [
78
__DIR__ . '/../../../autoload.php',
89
__DIR__ . '/../../vendor/autoload.php',
910
__DIR__ . '/../vendor/autoload.php'
1011
];
12+
$inflectorHelpers = [
13+
__DIR__ . '/../../../icanboogie/inflector/lib/helpers.php',
14+
__DIR__ . '/../../vendor/icanboogie/inflector/lib/helpers.php',
15+
__DIR__ . '/../vendor/icanboogie/inflector/lib/helpers.php'
16+
];
1117

1218
foreach ($files as $file) {
1319
if (file_exists($file)) {
@@ -16,12 +22,25 @@
1622
}
1723
}
1824

25+
foreach ($inflectorHelpers as $file) {
26+
if (file_exists($file)) {
27+
$inflectorHelper = $file;
28+
break;
29+
}
30+
}
31+
1932
if (! $autoload) {
2033
echo "Please install and update Composer before continuing." . PHP_EOL;
2134
exit(1);
2235
}
2336

24-
require $autoload;
37+
if (! $inflectorHelper) {
38+
echo "Error: Could not load inflector helper." . PHP_EOL;
39+
exit(1);
40+
}
41+
42+
require_once $autoload;
43+
require_once $inflectorHelper;
2544

2645
if (! isset($_SERVER['argv'][1])) {
2746
echo "Please specify the path to a config file." . PHP_EOL;

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
"rector/rector": "^1.0.0"
2929
},
3030
"autoload": {
31-
"classmap": ["src/"],
32-
"files": ["vendor/icanboogie/inflector/lib/helpers.php"]
31+
"classmap": ["src/"]
3332
},
3433
"autoload-dev": {
35-
"classmap": ["src/", "tests/"],
36-
"files": ["vendor/icanboogie/inflector/lib/helpers.php"]
34+
"classmap": ["src/", "tests/"]
3735
},
3836
"scripts": {
3937
"test": [

sample-config.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
'table_name_to_record_class_prefix_transformer' => // A callback that accepts a db table name, modifies it & returns the modified value that will be used to substitute {{{RECORD_CLASS_NAME_PREFIX}}} in template files
2424
function(string $tableName): string {
25-
26-
$inflector = \ICanBoogie\Inflector::get('en');
27-
$txtSeparatedWithSpaces = $inflector->titleize($tableName);
25+
26+
$txtSeparatedWithSpaces = \ICanBoogie\StaticInflector::titleize($tableName, 'en');
2827

2928
if(str_contains($txtSeparatedWithSpaces, ' ')) {
3029

@@ -35,13 +34,13 @@ function(string $tableName): string {
3534

3635
$singularizedWordsCamelCased .=
3736
strlen($word) > 1
38-
? $inflector->singularize($word)
37+
? \ICanBoogie\StaticInflector::singularize($word, 'en')
3938
: $word;
4039
}
4140

4241
} else {
4342

44-
$singularizedWordsCamelCased = $inflector->singularize($txtSeparatedWithSpaces);
43+
$singularizedWordsCamelCased = \ICanBoogie\StaticInflector::singularize($txtSeparatedWithSpaces, 'en');
4544
}
4645

4746
return $singularizedWordsCamelCased;
@@ -50,8 +49,7 @@ function(string $tableName): string {
5049
'table_name_to_collection_and_model_class_prefix_transformer' => // A callback that accepts a db table name, modifies it & returns the modified value that will be used to substitute {{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}} in template files
5150
function(string $tableName): string {
5251

53-
$inflector = \ICanBoogie\Inflector::get('en');
54-
$txtSeparatedWithSpaces = $inflector->titleize($tableName);
52+
$txtSeparatedWithSpaces = \ICanBoogie\StaticInflector::titleize($tableName, 'en');
5553

5654
if(str_contains($txtSeparatedWithSpaces, ' ')) {
5755

@@ -62,13 +60,13 @@ function(string $tableName): string {
6260

6361
$pluralizedWordsCamelCased .=
6462
strlen($word) > 1
65-
? $inflector->pluralize($word)
63+
? \ICanBoogie\StaticInflector::pluralize($word, 'en')
6664
: $word;
6765
}
6866

6967
} else {
7068

71-
$pluralizedWordsCamelCased = $inflector->pluralize($txtSeparatedWithSpaces);
69+
$pluralizedWordsCamelCased = \ICanBoogie\StaticInflector::pluralize($txtSeparatedWithSpaces, 'en');
7270
}
7371

7472
return $pluralizedWordsCamelCased;

tests/EndUserTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public function testThatScriptWorksAsExpected() {
7979
'table_name_to_record_class_prefix_transformer' => // A callback that accepts a db table name, modifies it & returns the modified value that will be used to substitute {{{RECORD_CLASS_NAME_PREFIX}}} in template files
8080
function(string $tableName): string {
8181

82-
$inflector = \ICanBoogie\Inflector::get('en');
83-
$txtSeparatedWithSpaces = $inflector->titleize($tableName);
82+
$txtSeparatedWithSpaces = \ICanBoogie\StaticInflector::titleize($tableName, 'en');
8483

8584
if(str_contains($txtSeparatedWithSpaces, ' ')) {
8685

@@ -91,13 +90,13 @@ function(string $tableName): string {
9190

9291
$singularizedWordsCamelCased .=
9392
strlen($word) > 1
94-
? $inflector->singularize($word)
93+
? \ICanBoogie\StaticInflector::singularize($word, 'en')
9594
: $word;
9695
}
9796

9897
} else {
9998

100-
$singularizedWordsCamelCased = $inflector->singularize($txtSeparatedWithSpaces);
99+
$singularizedWordsCamelCased = \ICanBoogie\StaticInflector::singularize($txtSeparatedWithSpaces, 'en');
101100
}
102101

103102
return $singularizedWordsCamelCased;
@@ -106,8 +105,7 @@ function(string $tableName): string {
106105
'table_name_to_collection_and_model_class_prefix_transformer' => // A callback that accepts a db table name, modifies it & returns the modified value that will be used to substitute {{{MODEL_OR_COLLECTION_CLASS_NAME_PREFIX}}} in template files
107106
function(string $tableName): string {
108107

109-
$inflector = \ICanBoogie\Inflector::get('en');
110-
$txtSeparatedWithSpaces = $inflector->titleize($tableName);
108+
$txtSeparatedWithSpaces = \ICanBoogie\StaticInflector::titleize($tableName, 'en');
111109

112110
if(str_contains($txtSeparatedWithSpaces, ' ')) {
113111

@@ -118,13 +116,13 @@ function(string $tableName): string {
118116

119117
$pluralizedWordsCamelCased .=
120118
strlen($word) > 1
121-
? $inflector->pluralize($word)
119+
? \ICanBoogie\StaticInflector::pluralize($word, 'en')
122120
: $word;
123121
}
124122

125123
} else {
126124

127-
$pluralizedWordsCamelCased = $inflector->pluralize($txtSeparatedWithSpaces);
125+
$pluralizedWordsCamelCased = \ICanBoogie\StaticInflector::pluralize($txtSeparatedWithSpaces, 'en');
128126
}
129127

130128
return $pluralizedWordsCamelCased;

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
error_reporting(E_ALL);
33

44
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'vendor/autoload.php';
5+
require_once dirname(__DIR__).DIRECTORY_SEPARATOR.'vendor/icanboogie/inflector/lib/helpers.php';
56

67
if( !file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'pdo.php') ) {
78

0 commit comments

Comments
 (0)