radebatz / property-info-extras
Property Info extras.
Installs: 1 328
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- ext-json: *
- phpunit/phpunit: >=8.0
- symfony/property-info: ^4.3|^5.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- php-coveralls/php-coveralls: ^2.2
This package is auto-updated.
Last update: 2024-11-24 06:41:27 UTC
README
Extensions for the Symfony property-info component.
- Magic class method extractor DocBlockMagicExtractor
- Support for merging results of multiple extractors where possible
Requirements
Installation
You can use Composer or simply Download the Release
Composer
The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.
Once composer is installed, execute the following command in your project root to install this library:
composer require radebatz/property-info-extras
Usage
Radebatz\PropertyInfoExtras\Extractor\DocBlockMagicExtractor
<?php use Radebatz\PropertyInfoExtras\Extractor\DocBlockCache; use Radebatz\PropertyInfoExtras\Extractor\DocBlockMagicExtractor; /** * @method string getProString() * @method void setProString(?string $proString) */ class MagicPopo { protected $properties = []; public function __call($method, $args) { $name = lcfirst(substr($method, 3)); if (0 == count($args)) { if (0 === strpos($method, 'get')) { return array_key_exists($name, $this->properties) ? $this->properties[$name] : null; } } elseif (1 == count($args)) { if (0 === strpos($method, 'set')) { $this->properties[$name] = $args[0]; return; } } throw new \RuntimeException(sprintf('Invalid method on: %s: method: "%s"', get_class($this), $method)); } } $phpDocMagicExtractor = new DocBlockMagicExtractor(new DocBlockCache()); $properties = $phpDocMagicExtractor->getProperties(MagicPopo::class); // ['proString']
Radebatz\PropertyInfoExtras\PropertyInfoExtraExtractor
Same as documented in The PropertyInfo Component
expect that Radebatz\PropertyInfoExtras\PropertyInfoExtraExtractor
provides the following additional xxAllxxx()
methods:
-
getAllProperties()
Total of properties reported. Order of extractors is relevant (last one wins).
-
getAllTypes()
Total of types reported. Merging is done on property level only in cases where later extractors add to the already extracted info (first one wins).
-
isAllReadable()
true
if at least one extractor returnstrue
. -
isAllWritable()
true
if at least one extractor returnstrue
.