wnx/laravel-stats
Composer 安装命令:
composer require wnx/laravel-stats
包简介
Get insights about your Laravel Project
关键字:
README 文档
README
Get insights about your Laravel Project.
Installing
The easiest way to install the package is by using composer.
composer require "wnx/laravel-stats" --dev
The package will automatically register itself.
Optionally, you can publish the config file in your Laravel applications with the following command:
php artisan vendor:publish --provider="Wnx\LaravelStats\StatsServiceProvider"
Usage
After installing you can generate the statistics by running the following Artisan Command.
php artisan stats
(Make sure you run php artisan config:clear before running the above command.)
The statistics are also available as JSON.
php artisan stats --json
If you want a more detailed report and see which classes have been grouped into which component, you can use the --verbose-option.
php artisan stats --verbose
The verbose option is available for the JSON format also.
php artisan stats --json --verbose
Note If your project is using Pest PHP for writing tests, these files will automatically be excluded from the statistics. Due to how "laravel-stats" works internally, Pest PHP tests can't currently be detected. See #194 for more information.
How does this package detect certain Laravel Components?
The package scans the files defined in the paths-array in the configuration file. It then applies Classifiers to those classes to determine which Laravel Component the class represents.
| Component | Classification |
|---|---|
| Livewire Components | Must extend Livewire\Component |
| Controller | Must be registered with a Route & does not extend Livewire\Component |
| Model | Must extend Illuminate\Database\Eloquent\Model |
| Command | Must extend Illuminate\Console\Command |
| Rule | Must extend Illuminate\Contracts\Validation\Rule |
| Policy | The Policy must be registered in your AuthServiceProvider |
| Middleware | The Middleware must be registered in your Http-Kernel |
| Event | Must use Illuminate\Foundation\Events\Dispatchable-Trait |
| Event Listener | Must be registered for an Event in EventServiceProvider |
Must extend Illuminate\Mail\Mailable |
|
| Notification | Must extend Illuminate\Notifications\Notification |
| Nova Action | Must extend Laravel\Nova\Actions\Action |
| Nova Dashboard | Must extend Laravel\Nova\Dashboard |
| Nova Filter | Must extend Laravel\Nova\Filters\Filter |
| Nova Lens | Must extend Laravel\Nova\Lenses\Lens |
| Nova Resource | Must extend Laravel\Nova\Resource |
| Job | Must use Illuminate\Foundation\Bus\Dispatchable-Trait |
| Migration | Must extend Illuminate\Database\Migrations\Migration |
| Request | Must extend Illuminate\Foundation\Http\FormRequest |
| Resource | Must extend Illuminate\Http\Resources\Json\JsonResource or Illuminate\Http\Resources\Json\ResourceCollection |
| Seeder | Must extend Illuminate\Database\Seeder |
| ServiceProvider | Must extend Illuminate\Support\ServiceProvider |
| Blade Components | Must extend Illuminate\View\Component |
| Custom Casts | Must implement Illuminate\Contracts\Database\Eloquent\CastsAttributes or Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes |
| Database Factory | Must extend Illuminate\Database\Eloquent\Factory |
| Dusk Tests | Must extend Laravel\Dusk\TestCase |
| BrowserKit Test | Must extend Laravel\BrowserKitTesting\TestCase |
| PHPUnit Test | Must extend PHPUnit\Framework\TestCase |
Create your own Classifiers
If your application has it's own components you would like to see in laravel-stats you can create your own "Classifiers".
Create your own Classifiers by implementing the Classifier-contract and adding the class to the stats.custom_component_classifier config array.
For example:
// app/Classifiers/RepositoryClassifier.php <?php namespace App\Classifiers; use Wnx\LaravelStats\ReflectionClass; use Wnx\LaravelStats\Contracts\Classifier; class RepositoryClassifier implements Classifier { public function name(): string { return 'Repositories'; } public function satisfies(ReflectionClass $class): bool { return $class->isSubclassOf(\App\Repositories\BaseRepository::class); } public function countsTowardsApplicationCode(): bool { return true; } public function countsTowardsTests(): bool { return false; } }
// config/stats.php <?php ... 'custom_component_classifier' => [ \App\Classifiers\RepositoryClassifier::class ], ...
Running the tests
The package has tests written in phpunit. You can run them with the following command.
./vendor/bin/phpunit
Running the command in a local test project
If you're working on the package locally and want to just run the command in a demo project you can use the composer path-repository format.
Add the following snippet to the composer.json in your demo project.
{
"repositories": [
{
"type": "path",
"url": "/path/to/laravel-stats/",
"options": {
"symlink": true
}
}
],
}
And "install" the package with composer require wnx/laravel-stats. The package should now be symlinked in your demo project.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Credits
License
This project is licensed under the MIT License - see the LICENSE file for details.
wnx/laravel-stats 适用场景与选型建议
wnx/laravel-stats 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82M 次下载、GitHub Stars 达 1.75k, 最近一次更新时间为 2017 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「stats」 「laravel」 「statistics」 「wnx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wnx/laravel-stats 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wnx/laravel-stats 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wnx/laravel-stats 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Helper to handle stats table with multiple formatter
The "View Counter" bundle
SPSS is a php-based implementation of IBM SPSS Statistics Standard. (Read/write SPSS, PSPP .sav files)
TYPO3 View-Statistics by coding.ms: Logs frontend actions in TYPO3 and displays them in a backend module. It tracks page views, news, downloads, and objects such as products or real estate, while custom objects can be configured via TypoScript. Frontend logins, login duration, user ID, IP address, a
Rserve client library for PHP
Partition problem for balanced arrays splitting made easy.
统计信息
- 总下载量: 1.82M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1751
- 点击次数: 29
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-26
