Skip to content

Commit d5aa1ca

Browse files
authored
[6.0] Replace all joomla/string inflector code (#45040)
* Replace all joomla/string inflector code * Replacing Joomla/String/Inflector class with Doctrine inflector everywhere
1 parent 235a71e commit d5aa1ca

File tree

11 files changed

+44
-30
lines changed

11 files changed

+44
-30
lines changed

administrator/components/com_categories/tmpl/categories/default.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
defined('_JEXEC') or die;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\HTML\HTMLHelper;
1415
use Joomla\CMS\Language\Multilanguage;
1516
use Joomla\CMS\Language\Text;
1617
use Joomla\CMS\Layout\LayoutHelper;
1718
use Joomla\CMS\Router\Route;
1819
use Joomla\CMS\Session\Session;
19-
use Joomla\String\Inflector;
2020

2121
/** @var \Joomla\Component\Categories\Administrator\View\Categories\HtmlView $this */
2222

@@ -38,10 +38,10 @@
3838
if (count($parts) > 1) {
3939
$section = $parts[1];
4040

41-
$inflector = Inflector::getInstance();
41+
$inflector = InflectorFactory::create()->build();
4242

43-
if (!$inflector->isPlural($section)) {
44-
$section = $inflector->toPlural($section);
43+
if ($inflector->pluralize($inflector->singularize($section)) !== $section) {
44+
$section = $inflector->pluralize($section);
4545
}
4646
}
4747

administrator/components/com_tags/tmpl/tags/default.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
defined('_JEXEC') or die;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Factory;
1415
use Joomla\CMS\HTML\HTMLHelper;
1516
use Joomla\CMS\Language\Multilanguage;
1617
use Joomla\CMS\Language\Text;
1718
use Joomla\CMS\Layout\LayoutHelper;
1819
use Joomla\CMS\Router\Route;
1920
use Joomla\CMS\Session\Session;
20-
use Joomla\String\Inflector;
2121

2222
/** @var \Joomla\Component\Tags\Administrator\View\Tags\HtmlView $this */
2323

@@ -40,10 +40,10 @@
4040

4141
if (count($parts) > 1) {
4242
$section = $parts[1];
43-
$inflector = Inflector::getInstance();
43+
$inflector = InflectorFactory::create()->build();
4444

45-
if (!$inflector->isPlural($section)) {
46-
$section = $inflector->toPlural($section);
45+
if ($inflector->pluralize($inflector->singularize($section)) !== $section) {
46+
$section = $inflector->pluralize($section);
4747
}
4848
}
4949

administrator/components/com_workflow/src/Controller/DisplayController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
namespace Joomla\Component\Workflow\Administrator\Controller;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Application\CMSApplication;
1415
use Joomla\CMS\Language\Text;
1516
use Joomla\CMS\MVC\Controller\BaseController;
1617
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
1718
use Joomla\CMS\Router\Route;
1819
use Joomla\Input\Input;
19-
use Joomla\String\Inflector;
2020

2121
// phpcs:disable PSR1.Files.SideEffects
2222
\defined('_JEXEC') or die;
@@ -110,7 +110,9 @@ public function display($cachable = false, $urlparams = [])
110110
$this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
111111
}
112112

113-
$url = 'index.php?option=com_workflow&view=' . Inflector::pluralize($view) . '&extension=' . $this->input->getCmd('extension');
113+
$inflector = InflectorFactory::create()->build();
114+
115+
$url = 'index.php?option=com_workflow&view=' . $inflector->pluralize($view) . '&extension=' . $this->input->getCmd('extension');
114116

115117
$this->setRedirect(Route::_($url, false));
116118

api/components/com_contact/src/Controller/ContactController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Joomla\Component\Contact\Api\Controller;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Component\ComponentHelper;
1415
use Joomla\CMS\Event\Contact\SubmitContactEvent;
1516
use Joomla\CMS\Event\Contact\ValidateContactEvent;
@@ -29,7 +30,6 @@
2930
use Joomla\CMS\User\UserFactoryAwareTrait;
3031
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
3132
use Joomla\Registry\Registry;
32-
use Joomla\String\Inflector;
3333
use PHPMailer\PHPMailer\Exception as phpMailerException;
3434
use Tobscure\JsonApi\Exception\InvalidParameterException;
3535

@@ -99,7 +99,8 @@ public function submitForm($id = null)
9999
$id = $this->input->post->get('id', 0, 'int');
100100
}
101101

102-
$modelName = Inflector::singularize($this->contentType);
102+
$inflector = InflectorFactory::create()->build();
103+
$modelName = $inflector->singularize($this->contentType);
103104

104105
/** @var \Joomla\Component\Contact\Site\Model\ContactModel $model */
105106
$model = $this->getModel($modelName, 'Site');

api/components/com_languages/src/Controller/OverridesController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
namespace Joomla\Component\Languages\Api\Controller;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Form\Form;
1415
use Joomla\CMS\Language\Text;
1516
use Joomla\CMS\MVC\Controller\ApiController;
1617
use Joomla\CMS\MVC\Controller\Exception;
17-
use Joomla\String\Inflector;
1818
use Tobscure\JsonApi\Exception\InvalidParameterException;
1919

2020
// phpcs:disable PSR1.Files.SideEffects
@@ -87,8 +87,11 @@ public function displayList()
8787
*/
8888
protected function save($recordKey = null)
8989
{
90+
$inflector = InflectorFactory::create()->build();
91+
$modelName = $inflector->singularize($this->contentType);
92+
9093
/** @var \Joomla\CMS\MVC\Model\AdminModel $model */
91-
$model = $this->getModel(Inflector::singularize($this->contentType));
94+
$model = $this->getModel($modelName);
9295

9396
if (!$model) {
9497
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));

api/components/com_media/src/Controller/MediaController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Joomla\Component\Media\Api\Controller;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Access\Exception\NotAllowed;
1415
use Joomla\CMS\Component\ComponentHelper;
1516
use Joomla\CMS\Filter\InputFilter;
@@ -19,7 +20,6 @@
1920
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
2021
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;
2122
use Joomla\Component\Media\Api\Model\MediumModel;
22-
use Joomla\String\Inflector;
2323
use Tobscure\JsonApi\Exception\InvalidParameterException;
2424

2525
// phpcs:disable PSR1.Files.SideEffects
@@ -314,7 +314,8 @@ protected function allowEdit($data = [], $key = 'id'): bool
314314
protected function save($recordKey = null)
315315
{
316316
// Explicitly get the single item model name.
317-
$modelName = $this->input->get('model', Inflector::singularize($this->contentType));
317+
$inflector = InflectorFactory::create()->build();
318+
$modelName = $this->input->get('model', $inflector->singularize($this->contentType));
318319

319320
/** @var MediumModel $model */
320321
$model = $this->getModel($modelName, '', ['ignore_request' => true, 'state' => $this->modelState]);
@@ -377,7 +378,8 @@ public function delete($id = null): void
377378

378379
$this->modelState->set('path', $this->input->get('path', '', 'STRING'));
379380

380-
$modelName = $this->input->get('model', Inflector::singularize($this->contentType));
381+
$inflector = InflectorFactory::create()->build();
382+
$modelName = $this->input->get('model', $inflector->singularize($this->contentType));
381383
$model = $this->getModel($modelName, '', ['ignore_request' => true, 'state' => $this->modelState]);
382384

383385
$model->delete();

api/components/com_plugins/src/Controller/PluginsController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
namespace Joomla\Component\Plugins\Api\Controller;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Filter\InputFilter;
1415
use Joomla\CMS\Language\Text;
1516
use Joomla\CMS\MVC\Controller\ApiController;
1617
use Joomla\CMS\MVC\Controller\Exception;
1718
use Joomla\CMS\Router\Exception\RouteNotFoundException;
18-
use Joomla\String\Inflector;
1919
use Tobscure\JsonApi\Exception\InvalidParameterException;
2020

2121
// phpcs:disable PSR1.Files.SideEffects
@@ -70,7 +70,8 @@ public function edit()
7070
}
7171

7272
/** @var \Joomla\Component\Plugins\Administrator\Model\PluginModel $model */
73-
$model = $this->getModel(Inflector::singularize($this->contentType), '', ['ignore_request' => true]);
73+
$inflector = InflectorFactory::create()->build();
74+
$model = $this->getModel($inflector->singularize($this->contentType), '', ['ignore_request' => true]);
7475

7576
if (!$model) {
7677
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));

api/components/com_templates/src/Controller/StylesController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
namespace Joomla\Component\Templates\Api\Controller;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\MVC\Controller\ApiController;
14-
use Joomla\String\Inflector;
1515
use Tobscure\JsonApi\Exception\InvalidParameterException;
1616

1717
// phpcs:disable PSR1.Files.SideEffects
@@ -91,7 +91,8 @@ protected function preprocessSaveData(array $data): array
9191
unset($data['template']);
9292
}
9393

94-
$model = $this->getModel(Inflector::singularize($this->contentType), '', ['ignore_request' => true]);
94+
$inflector = InflectorFactory::create()->build();
95+
$model = $this->getModel($inflector->singularize($this->contentType), '', ['ignore_request' => true]);
9596
$data['template'] = $model->getItem($this->input->getInt('id'))->template;
9697
}
9798

libraries/src/MVC/Controller/ApiController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Joomla\CMS\MVC\Controller;
1111

12+
use Doctrine\Inflector\InflectorFactory;
1213
use Joomla\CMS\Access\Exception\NotAllowed;
1314
use Joomla\CMS\Application\CMSWebApplicationInterface;
1415
use Joomla\CMS\Component\ComponentHelper;
@@ -19,7 +20,6 @@
1920
use Joomla\CMS\MVC\View\JsonApiView;
2021
use Joomla\Input\Input;
2122
use Joomla\Registry\Registry;
22-
use Joomla\String\Inflector;
2323
use Tobscure\JsonApi\Exception\InvalidParameterException;
2424

2525
// phpcs:disable PSR1.Files.SideEffects
@@ -163,7 +163,8 @@ public function displayItem($id = null)
163163
throw new \RuntimeException($e->getMessage());
164164
}
165165

166-
$modelName = $this->input->get('model', Inflector::singularize($this->contentType));
166+
$inflector = InflectorFactory::create()->build();
167+
$modelName = $this->input->get('model', $inflector->singularize($this->contentType));
167168

168169
// Create the model, ignoring request data so we can safely set the state in the request from the controller
169170
$model = $this->getModel($modelName, '', ['ignore_request' => true, 'state' => $this->modelState]);
@@ -287,7 +288,8 @@ public function delete($id = null)
287288
$id = $this->input->get('id', 0, 'int');
288289
}
289290

290-
$modelName = $this->input->get('model', Inflector::singularize($this->contentType));
291+
$inflector = InflectorFactory::create()->build();
292+
$modelName = $this->input->get('model', $inflector->singularize($this->contentType));
291293

292294
/** @var \Joomla\CMS\MVC\Model\AdminModel $model */
293295
$model = $this->getModel($modelName, '', ['ignore_request' => true]);
@@ -339,7 +341,8 @@ public function add()
339341
public function edit()
340342
{
341343
/** @var \Joomla\CMS\MVC\Model\AdminModel $model */
342-
$model = $this->getModel(Inflector::singularize($this->contentType));
344+
$inflector = InflectorFactory::create()->build();
345+
$model = $this->getModel($inflector->singularize($this->contentType));
343346

344347
if (!$model) {
345348
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));
@@ -388,7 +391,8 @@ public function edit()
388391
protected function save($recordKey = null)
389392
{
390393
/** @var \Joomla\CMS\MVC\Model\AdminModel $model */
391-
$model = $this->getModel(Inflector::singularize($this->contentType));
394+
$inflector = InflectorFactory::create()->build();
395+
$model = $this->getModel($inflector->singularize($this->contentType));
392396

393397
if (!$model) {
394398
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));

plugins/workflow/featuring/src/Extension/Featuring.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Joomla\Plugin\Workflow\Featuring\Extension;
1212

13+
use Doctrine\Inflector\InflectorFactory;
1314
use Joomla\CMS\Event\AbstractEvent;
1415
use Joomla\CMS\Event\Model;
1516
use Joomla\CMS\Event\Table\BeforeStoreEvent;
@@ -28,7 +29,6 @@
2829
use Joomla\Event\EventInterface;
2930
use Joomla\Event\SubscriberInterface;
3031
use Joomla\Registry\Registry;
31-
use Joomla\String\Inflector;
3232

3333
// phpcs:disable PSR1.Files.SideEffects
3434
\defined('_JEXEC') or die;
@@ -194,7 +194,7 @@ public function onAfterDisplay(DisplayEvent $event)
194194
$section = $event->getArgument('section');
195195

196196
// We need the single model context for checking for workflow
197-
$singularsection = Inflector::singularize($section);
197+
$singularsection = InflectorFactory::create()->build()->singularize($section);
198198

199199
if (!$this->isSupported($component . '.' . $singularsection)) {
200200
return;

0 commit comments

Comments
 (0)