Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
slince committed Oct 22, 2023
1 parent ac5e8c6 commit 418d663
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}
],
"require": {
"php": "8.0",
"doctrine/inflector": "^1.2|^2.0",
"doctrine/cache": "^1.0",
"php": ">=8.2",
"doctrine/inflector": "^2.0",
"doctrine/cache": "^2.2",
"guzzlehttp/guzzle": "^7.0",
"slince/di": "^3.0",
"symfony/yaml": "^4.2|^5.0|^6.0",
"jms/serializer": "^3.10"
"jms/serializer": "^3.28"
},
"require-dev": {
"phpunit/phpunit": "^7.5|^8.0|^9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function __construct($shop, CredentialInterface $credential, array $optio

public function __call($name, $arguments)
{
if ('Manager' === substr($name, -7)) {
if (str_ends_with($name, 'Manager')) {
$serviceId = substr($name, 3, -7);
$serviceId = Inflector::tableize(Inflector::pluralize($serviceId));
return $this->container->get($serviceId);
Expand Down
61 changes: 27 additions & 34 deletions src/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,42 @@

namespace Slince\Shopify;

use Doctrine\Common\Inflector\Inflector as LegacyInflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\Inflector\Inflector as DoctrineInflector;

if (class_exists(InflectorFactory::class)) {
final class Inflector
final class Inflector
{
/**
* @var DoctrineInflector|null
*/
protected static ?DoctrineInflector $inflector = null;

protected static function getInflector(): DoctrineInflector
{
/**
* @var \Doctrine\Inflector\Inflector
*/
protected static $inflector;

protected static function getInflector(): \Doctrine\Inflector\Inflector
{
if (null !== Inflector::$inflector) {
return Inflector::$inflector;
}
return Inflector::$inflector = InflectorFactory::create()->build();
if (null !== Inflector::$inflector) {
return Inflector::$inflector;
}
return Inflector::$inflector = InflectorFactory::create()->build();
}

public static function pluralize(string $word): string
{
return static::getInflector()->pluralize($word);
}
public static function pluralize(string $word): string
{
return Inflector::getInflector()->pluralize($word);
}

public static function tableize(string $word): string
{
return static::getInflector()->tableize($word);
}
public static function tableize(string $word): string
{
return Inflector::getInflector()->tableize($word);
}

public static function classify(string $word): string
{
return static::getInflector()->classify($word);
}
public static function classify(string $word): string
{
return Inflector::getInflector()->classify($word);
}


public static function singularize(string $word)
{
return static::getInflector()->singularize($word);
}
}
} else {
final class Inflector extends LegacyInflector
public static function singularize(string $word)
{

return Inflector::getInflector()->singularize($word);
}
}

0 comments on commit 418d663

Please sign in to comment.