generated from yii-tools/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(helper): Add Reflector helper for class, property, type, and attribute metadata introspection.
#9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(helper): Add Reflector helper for class, property, type, and attribute metadata introspection.
#9
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d98d249
feat(helper): Add `Reflector` helper for class, property, type, and a…
terabytesoftw aaaa39c
Apply Coderabbitai Nitpick comments.
terabytesoftw 4791853
Apply fixed Coderabbitai review.
terabytesoftw d5e5ec9
Apply fixed Coderabbitai review.
terabytesoftw 85aecc7
Apply fixes from StyleCI
StyleCIBot 22627af
Apply fixed Coderabbitai review.
terabytesoftw 9d23dc6
Apply fixed Coderabbitai review.
terabytesoftw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Usage examples | ||
|
|
||
| This document provides practical examples for word conversion, password generation, time zones, and reflection metadata. | ||
|
|
||
| ## Convert camelCase to snake_case | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\WordCaseConverter; | ||
|
|
||
| $word = WordCaseConverter::camelToSnake('dateBirth'); | ||
| // date_birth | ||
| ``` | ||
|
|
||
| ## Convert snake_case to camelCase | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\WordCaseConverter; | ||
|
|
||
| $word = WordCaseConverter::snakeToCamel('date_birth'); | ||
| // dateBirth | ||
| ``` | ||
|
|
||
| ## Convert text to title words | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\WordCaseConverter; | ||
|
|
||
| $word = WordCaseConverter::toTitleWords('dateOfMessage'); | ||
| // Date Of Message | ||
| ``` | ||
|
|
||
| ## Generate passwords | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\PasswordGenerator; | ||
|
|
||
| $password = PasswordGenerator::generate(12); | ||
| // e.g. aB3#kL9!mN2@ | ||
| ``` | ||
|
|
||
| ## Retrieve all time zones | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\TimeZoneList; | ||
|
|
||
| $timezones = TimeZoneList::all(); | ||
| // [['timezone' => 'Pacific/Midway', 'name' => 'Pacific/Midway (UTC -11:00)', 'offset' => -39600], ...] | ||
| ``` | ||
|
|
||
| ## Inspect class metadata with Reflector | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\Reflector; | ||
|
|
||
| $shortName = Reflector::shortName(\App\Domain\User::class); | ||
| $hasEmail = Reflector::hasProperty(\App\Domain\User::class, 'email'); | ||
| $typeNames = Reflector::propertyTypeNames(\App\Domain\User::class, 'email'); | ||
| $attributes = Reflector::propertyAttributes(\App\Domain\User::class, 'email'); | ||
| ``` | ||
|
|
||
| ## Reflector cache lifecycle in long-running workers | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App; | ||
|
|
||
| use PHPForge\Helper\Reflector; | ||
|
|
||
| $size = Reflector::cacheSize(); | ||
|
|
||
| if ($size > 400) { | ||
| Reflector::clearCache(); | ||
| } | ||
| ``` | ||
|
|
||
| ## Next steps | ||
|
|
||
| - 📚 [Installation guide](installation.md) | ||
| - 🧪 [Testing guide](testing.md) | ||
| - 🛠️ [Development guide](development.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Installation guide | ||
|
|
||
| ## System requirements | ||
|
|
||
| - [`PHP`](https://www.php.net/downloads) 8.1 or higher. | ||
| - [`Composer`](https://getcomposer.org/download/) for dependency management. | ||
|
|
||
| ## Installation | ||
|
|
||
| ### Method 1: Using [Composer](https://getcomposer.org/download/) (recommended) | ||
|
|
||
| Install the package. | ||
|
|
||
| ```bash | ||
| composer require php-forge/helper:^0.2 | ||
| ``` | ||
|
|
||
| ### Method 2: Manual installation | ||
|
|
||
| Add to your `composer.json`. | ||
|
|
||
| ```json | ||
| { | ||
| "require": { | ||
| "php-forge/helper": "^0.2" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Then run. | ||
|
|
||
| ```bash | ||
| composer update | ||
| ``` | ||
|
|
||
| ## Next steps | ||
|
|
||
| - 💡 [Usage examples](examples.md) | ||
| - 🧪 [Testing guide](testing.md) | ||
| - 🛠️ [Development guide](development.md) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.