reformo / backendbase-utility
Standard Library for Backendbase libraries.
Installs: 2 956
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- ext-dom: *
- psr/container: ^1.0|^2.0
Requires (Dev)
- codeception/codeception: ^5.0
- codeception/module-asserts: ^2.0
- doctrine/coding-standard: ^9.0
- laminas/laminas-servicemanager: ^3.6
- php-coveralls/php-coveralls: ^v2.2.0
- squizlabs/php_codesniffer: ^3.6
Suggests
- ext-intl: Slugify needs this extension
- ext-libxml: TagAndAttributeRemover needs this extention
README
Standard Library for Backendbase and other libraries.
EqualsBuilder
This class provides methods to build a equals method for any class. Intended to be use to compare Value Objects.
<?php declare(strict_types=1); use Backendbase\Utility\EqualsBuilder; class SomeValueObject() { private $value1; private $value2; public function __construct(string $value1, string $value2) { $this->value1 = $value1; $this->value2 = $value2; } public function getValue1() :string { return $value1; } public function getValue2() : string { return $value2; } public function equals($otherObject) : bool { return EqualsBuilder::create() ->append($this->value1, $otherObject->getValue1()) ->append($this->value2, $otherObject->getValue2()) ->isEquals(); } }
Resolver
This class provides a method to obtain typehints of a method. Intended to be used to autowire classes.
<?php declare(strict_types=1); use Backendbase\Utility\Resolver; class BlogService {} class Controller { private $argument; private $service; public function __construct(BlogService $service, array $argument) { $this->service = $service; $this->argument = $argument; } } $arguments = Resolver::getParameterHints(Controller::class, '__construct'); var_dump($arguments); /* Prints array(2) { ["service"]=> string(11) "BlogService" ["argument"]=> string(5) "array" } */
CaseConverter
This class provides methods to convert strings to camelCase, PascalCase or snake_case string.
<?php declare(strict_types=1); use Backendbase\Utility\CaseConverter; $source = 'test string'; $result = CaseConverter::toCamelCase($source); // returns: testString $result = CaseConverter::toPascalCase($source); // returns: TestString $result = CaseConverter::toSnakeCase($source); // returns: test_string
Git\Version
This class provides a methods to get short version of git. For deployments using git, it can be used to give version numbers to JS, CSS files to ensure to cache updated version of these files.
<?php // common.php declare(strict_types=1); use Backendbase\Utility\Git\Version; $gitVersion = Version::short(); $twig->addGlobal('version', $gitVersion);
<!-- main.twig --> <html> <head> <link href="/assets/css/main.css?v={{version}}" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="/assets/js/main.min.js?v={{version}}"></script> </head> <body> ... </body> </html>
BaseUrlExtractor
This class provides a methods to get base url where applications runs.
Caution: This method may not return real base url if you are behind some services like Cloudflare and when you use Flexible SSL feature.
<?php declare(strict_types=1); use Backendbase\Utility\BaseUrlExtractor; $baseUrl = BaseUrlExtractor::getBaseUrl($_SERVER); echo $baseUrl; /* Prints base url like: http://127.0.0.1:8080 http://127.0.0.1:8080/myapp https://myapp.com */