mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Compare commits
105
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b1273c45e | ||
|
|
08d39c125f | ||
|
|
87a02ff574 | ||
|
|
9e42ce11f4 | ||
|
|
dca7fa7b10 | ||
|
|
0e4b9b77c3 | ||
|
|
46901d2c80 | ||
|
|
25b5576f57 | ||
|
|
d6d99994c3 | ||
|
|
7e78d02d0a | ||
|
|
35d954fc39 | ||
|
|
5eeda63958 | ||
|
|
b76156b24c | ||
|
|
2a63d51496 | ||
|
|
3814fe86ca | ||
|
|
3ab73555d9 | ||
|
|
ff3844e4e1 | ||
|
|
d11bf58084 | ||
|
|
75e1f22ec6 | ||
|
|
144a50e8ee | ||
|
|
b611cb5eff | ||
|
|
e82de98cef | ||
|
|
456853be46 | ||
|
|
25c8de637d | ||
|
|
5a841a209d | ||
|
|
56660cab84 | ||
|
|
555d3e3700 | ||
|
|
963ead0a01 | ||
|
|
8c306035aa | ||
|
|
f1e93f042d | ||
|
|
5280b47750 | ||
|
|
525733122e | ||
|
|
a7fc2ec489 | ||
|
|
8caca941b3 | ||
|
|
e96943fe6f | ||
|
|
df3ecb2843 | ||
|
|
105f14a50d | ||
|
|
5fad258f5d | ||
|
|
13e65d3885 | ||
|
|
22612733a2 | ||
|
|
dc476f9736 | ||
|
|
71cb03ca6a | ||
|
|
abe2df5853 | ||
|
|
2de6ab6038 | ||
|
|
c229335651 | ||
|
|
495361e501 | ||
|
|
7583353915 | ||
|
|
16c570c589 | ||
|
|
884eaeeb1a | ||
|
|
b6706683b2 | ||
|
|
6f9b90c204 | ||
|
|
e1a0f034a1 | ||
|
|
b75f879383 | ||
|
|
ad800d197f | ||
|
|
f3a3533b2d | ||
|
|
e938cd3a31 | ||
|
|
f8c6ec95f6 | ||
|
|
0a4ff969d2 | ||
|
|
4b47c0b61c | ||
|
|
7598293bc6 | ||
|
|
035b14176b | ||
|
|
cb08c6ff81 | ||
|
|
28af7cd19c | ||
|
|
8f004f5d6b | ||
|
|
da677f1ba5 | ||
|
|
321844d9a5 | ||
|
|
928389d7a4 | ||
|
|
dbfcfd66c5 | ||
|
|
a9484c67d1 | ||
|
|
3064296216 | ||
|
|
f057a4f820 | ||
|
|
091f78508c | ||
|
|
cf4fcd810c | ||
|
|
d3203de671 | ||
|
|
093171e01f | ||
|
|
2d82419167 | ||
|
|
0e84805e37 | ||
|
|
7a07515149 | ||
|
|
bae462604e | ||
|
|
b28c8cbae1 | ||
|
|
d734ecabcc | ||
|
|
4f227d5c57 | ||
|
|
35ebf3a2ba | ||
|
|
f7b31bdbdc | ||
|
|
8de1673535 | ||
|
|
d818b72f82 | ||
|
|
e97ed532f0 | ||
|
|
606183ea12 | ||
|
|
a72cd81e5f | ||
|
|
f1ebd847aa | ||
|
|
83597196f9 | ||
|
|
19553f63e4 | ||
|
|
f50470ba49 | ||
|
|
7762e07f0a | ||
|
|
467b5f5b5f | ||
|
|
c213be3d3c | ||
|
|
4b8ba85b34 | ||
|
|
d4c0ae5851 | ||
|
|
3a01e351de | ||
|
|
add34665a8 | ||
|
|
c77752bb58 | ||
|
|
aa8f772a46 | ||
|
|
0c4c55f349 | ||
|
|
ed972acf19 | ||
|
|
4069863d0c |
@@ -0,0 +1,15 @@
|
|||||||
|
; This file is for unifying the coding style for different editors and IDEs.
|
||||||
|
; More information at http://editorconfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Path-based git attributes
|
||||||
|
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
|
||||||
|
|
||||||
|
# Ignore all test and documentation with "export-ignore".
|
||||||
|
/.gitattributes export-ignore
|
||||||
|
/.gitignore export-ignore
|
||||||
|
/.travis.yml export-ignore
|
||||||
|
/phpunit.xml.dist export-ignore
|
||||||
|
/.scrutinizer.yml export-ignore
|
||||||
|
/tests export-ignore
|
||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
/vendor
|
build
|
||||||
|
vendor
|
||||||
composer.lock
|
composer.lock
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
filter:
|
||||||
|
excluded_paths: [tests/*]
|
||||||
|
|
||||||
|
checks:
|
||||||
|
php:
|
||||||
|
remove_extra_empty_lines: true
|
||||||
|
remove_php_closing_tag: true
|
||||||
|
remove_trailing_whitespace: true
|
||||||
|
fix_use_statements:
|
||||||
|
remove_unused: true
|
||||||
|
preserve_multiple: false
|
||||||
|
preserve_blanklines: true
|
||||||
|
order_alphabetically: true
|
||||||
|
fix_php_opening_tag: true
|
||||||
|
fix_linefeed: true
|
||||||
|
fix_line_ending: true
|
||||||
|
fix_identation_4spaces: true
|
||||||
|
fix_doc_comments: true
|
||||||
|
|
||||||
|
tools:
|
||||||
|
external_code_coverage:
|
||||||
|
timeout: 600
|
||||||
|
runs: 3
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
preset: psr2
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
language: php
|
||||||
|
|
||||||
|
php:
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
- 7.0
|
||||||
|
- 7.1
|
||||||
|
|
||||||
|
# This triggers builds to run on the new TravisCI infrastructure.
|
||||||
|
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
## Cache composer
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.composer/cache
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- php: 5.5
|
||||||
|
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
|
||||||
|
|
||||||
|
script:
|
||||||
|
- vendor/bin/phpcs --standard=psr2 src/
|
||||||
|
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
|
||||||
|
|
||||||
|
after_script:
|
||||||
|
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
# The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Barry vd. Heuvel <barryvdh@gmail.com>
|
||||||
|
|
||||||
|
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
> of this software and associated documentation files (the "Software"), to deal
|
||||||
|
> in the Software without restriction, including without limitation the rights
|
||||||
|
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
> copies of the Software, and to permit persons to whom the Software is
|
||||||
|
> furnished to do so, subject to the following conditions:
|
||||||
|
>
|
||||||
|
> The above copyright notice and this permission notice shall be included in
|
||||||
|
> all copies or substantial portions of the Software.
|
||||||
|
>
|
||||||
|
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
> THE SOFTWARE.
|
||||||
+25
-6
@@ -11,13 +11,18 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4.0",
|
"php": ">=5.4.0",
|
||||||
"illuminate/support": "5.0.x|5.1.x|5.2.x",
|
"illuminate/support": "^5.0,<5.6",
|
||||||
"illuminate/console": "5.0.x|5.1.x|5.2.x",
|
"illuminate/console": "^5.0,<5.6",
|
||||||
"illuminate/filesystem": "5.0.x|5.1.x|5.2.x",
|
"illuminate/filesystem": "^5.0,<5.6",
|
||||||
"phpdocumentor/reflection-docblock": "2.0.4",
|
"barryvdh/reflection-docblock": "^2.0.4",
|
||||||
"symfony/class-loader": "~2.3|~3.0"
|
"symfony/class-loader": "^2.3|^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"illuminate/config": "^5.0,<5.6",
|
||||||
|
"illuminate/view": "^5.0,<5.6",
|
||||||
|
"phpunit/phpunit" : "4.*",
|
||||||
|
"scrutinizer/ocular": "~1.1",
|
||||||
|
"squizlabs/php_codesniffer": "~2.3",
|
||||||
"doctrine/dbal": "~2.3"
|
"doctrine/dbal": "~2.3"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
@@ -28,9 +33,23 @@
|
|||||||
"Barryvdh\\LaravelIdeHelper\\": "src"
|
"Barryvdh\\LaravelIdeHelper\\": "src"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
":vendor\\:package_name\\": "tests"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "phpunit",
|
||||||
|
"cs": "phpcs --standard=psr2 src/"
|
||||||
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "2.1-dev"
|
"dev-master": "2.3-dev"
|
||||||
|
},
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+63
-3
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|
||||||
@@ -14,6 +14,28 @@ return array(
|
|||||||
'filename' => '_ide_helper',
|
'filename' => '_ide_helper',
|
||||||
'format' => 'php',
|
'format' => 'php',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Fluent helpers
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Set to true to generate commonly used Fluent methods
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'include_fluent' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Write Model Magic methods
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Set to false to disable write magic methods of model
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'write_model_magic_where' => true,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Helper files to include
|
| Helper files to include
|
||||||
@@ -71,7 +93,7 @@ return array(
|
|||||||
'emergency' => 'Monolog\Logger::addEmergency',
|
'emergency' => 'Monolog\Logger::addEmergency',
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Interface implementations
|
| Interface implementations
|
||||||
@@ -81,7 +103,7 @@ return array(
|
|||||||
| are detected by the helpers, others can be listed below.
|
| are detected by the helpers, others can be listed below.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'interfaces' => array(
|
'interfaces' => array(
|
||||||
|
|
||||||
),
|
),
|
||||||
@@ -116,4 +138,42 @@ return array(
|
|||||||
|
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Support for camel cased models
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| There are some Laravel packages (such as Eloquence) that allow for accessing
|
||||||
|
| Eloquent model properties via camel case, instead of snake case.
|
||||||
|
|
|
||||||
|
| Enabling this option will support these packages by saving all model
|
||||||
|
| properties as camel case, instead of snake case.
|
||||||
|
|
|
||||||
|
| For example, normally you would see this:
|
||||||
|
|
|
||||||
|
| * @property \Carbon\Carbon $created_at
|
||||||
|
| * @property \Carbon\Carbon $updated_at
|
||||||
|
|
|
||||||
|
| With this enabled, the properties will be this:
|
||||||
|
|
|
||||||
|
| * @property \Carbon\Carbon $createdAt
|
||||||
|
| * @property \Carbon\Carbon $updatedAt
|
||||||
|
|
|
||||||
|
| Note, it is currently an all-or-nothing option.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'model_camel_case_properties' => false,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Property Casts
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Cast the given "real type" to the given "type".
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'type_overrides' => array(
|
||||||
|
'integer' => 'int',
|
||||||
|
'boolean' => 'bool',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit bootstrap="vendor/autoload.php"
|
||||||
|
backupGlobals="false"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
colors="true"
|
||||||
|
verbose="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="false">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name=":vendor Test Suite">
|
||||||
|
<directory>tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">src/</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
<logging>
|
||||||
|
<log type="tap" target="build/report.tap"/>
|
||||||
|
<log type="junit" target="build/report.junit.xml"/>
|
||||||
|
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
|
||||||
|
<log type="coverage-text" target="build/coverage.txt"/>
|
||||||
|
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||||
|
</logging>
|
||||||
|
</phpunit>
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
## Laravel 5 IDE Helper Generator
|
## Laravel 5 IDE Helper Generator
|
||||||
[](https://packagist.org/packages/barryvdh/laravel-ide-helper) [](https://packagist.org/packages/barryvdh/laravel-ide-helper)
|
|
||||||
|
[![Latest Version on Packagist][ico-version]][link-packagist]
|
||||||
|
[![Software License][ico-license]](LICENSE.md)
|
||||||
|
[![Build Status][ico-travis]][link-travis]
|
||||||
|
[![Total Downloads][ico-downloads]][link-downloads]
|
||||||
|
|
||||||
__For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)__
|
__For Laravel 4.x, check [version 1.11](https://github.com/barryvdh/laravel-ide-helper/tree/1.11)__
|
||||||
|
|
||||||
### Complete phpDocs, directly from the source
|
### Complete phpDocs, directly from the source
|
||||||
|
|
||||||
_Checkout [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
_Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_
|
||||||
|
|
||||||
* [`php artisan ide-helper:generate` - phpDoc generation for Laravel Facades ](#automatic-phpdoc-generation-for-laravel-facades)
|
* [`php artisan ide-helper:generate` - phpDoc generation for Laravel Facades ](#automatic-phpdoc-generation-for-laravel-facades)
|
||||||
* [`php artisan ide-helper:models` - phpDocs for models](#automatic-phpdocs-for-models)
|
* [`php artisan ide-helper:models` - phpDocs for models](#automatic-phpdocs-for-models)
|
||||||
@@ -34,8 +38,27 @@ After updating composer, add the service provider to the `providers` array in `c
|
|||||||
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
|
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
|
||||||
```
|
```
|
||||||
|
|
||||||
### Automatic phpDoc generation for Laravel Facades
|
To install this package on only development systems, add the `--dev` flag to your composer command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
composer require --dev barryvdh/laravel-ide-helper
|
||||||
|
```
|
||||||
|
|
||||||
|
In Laravel, instead of adding the service provider in the `config/app.php` file, you can add the following code to your `app/Providers/AppServiceProvider.php` file, within the `register()` method:
|
||||||
|
|
||||||
|
```php
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
if ($this->app->environment() !== 'production') {
|
||||||
|
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This will allow your application to load the Laravel IDE Helper on non-production enviroments.
|
||||||
|
|
||||||
|
### Automatic phpDoc generation for Laravel Facades
|
||||||
|
|
||||||
You can now re-generate the docs yourself (for future updates)
|
You can now re-generate the docs yourself (for future updates)
|
||||||
|
|
||||||
@@ -50,8 +73,9 @@ You can configure your composer.json to do this after each commit:
|
|||||||
```js
|
```js
|
||||||
"scripts":{
|
"scripts":{
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"php artisan clear-compiled",
|
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
|
||||||
"php artisan ide-helper:generate",
|
"php artisan ide-helper:generate",
|
||||||
|
"php artisan ide-helper:meta",
|
||||||
"php artisan optimize"
|
"php artisan optimize"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -66,10 +90,10 @@ php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServic
|
|||||||
The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.
|
The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.
|
||||||
|
|
||||||
Some classes need a working database connection. If you do not have a default working connection, some facades will not be included.
|
Some classes need a working database connection. If you do not have a default working connection, some facades will not be included.
|
||||||
You can use an in-memory SQLite driver, using the -M option.
|
You can use an in-memory SQLite driver by adding the `-M` option.
|
||||||
|
|
||||||
You can choose to include helper files. This is not enabled by default, but you can override it with the `--helpers (-H)` option.
|
You can choose to include helper files. This is not enabled by default, but you can override it with the `--helpers (-H)` option.
|
||||||
The `Illuminate/Support/helpers.php` is already set-up, but you can add/remove your own files in the config file.
|
The `Illuminate/Support/helpers.php` is already set up, but you can add/remove your own files in the config file.
|
||||||
|
|
||||||
### Automatic phpDocs for models
|
### Automatic phpDocs for models
|
||||||
|
|
||||||
@@ -125,11 +149,29 @@ Models can be ignored using the `--ignore (-I)` option
|
|||||||
php artisan ide-helper:models --ignore="Post,User"
|
php artisan ide-helper:models --ignore="Post,User"
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: With namespaces, wrap your model name in " signs: `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`)
|
||||||
|
|
||||||
|
For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add
|
||||||
|
```php
|
||||||
|
/** @mixin \Eloquent */
|
||||||
|
```
|
||||||
|
for your model class.
|
||||||
|
|
||||||
|
### Automatic phpDocs generation for Laravel Fluent methods
|
||||||
|
If you need phpDocs support for Fluent methods in migration, for example
|
||||||
|
```php
|
||||||
|
$table->string("somestring")->nullable()->index();
|
||||||
|
```
|
||||||
|
After publishing vendor, simply change the `include_fluent` line your `config/ide-helper.php` file into:
|
||||||
|
```php
|
||||||
|
'include_fluent' => true,
|
||||||
|
```
|
||||||
|
And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE now.
|
||||||
|
|
||||||
|
|
||||||
## PhpStorm Meta for Container instances
|
## PhpStorm Meta for Container instances
|
||||||
|
|
||||||
It's possible to generate a PhpStorm meta file, to [add support for factory design pattern](https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata). For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container. For example, `events` will return an `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
It's possible to generate a PhpStorm meta file to [add support for factory design pattern](https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata). For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container. For example, `events` will return an `Illuminate\Events\Dispatcher` object, so with the meta file you can call `app('events')` and it will autocomplete the Dispatcher methods.
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
php artisan ide-helper:meta
|
php artisan ide-helper:meta
|
||||||
@@ -151,6 +193,70 @@ Pre-generated example: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67
|
|||||||
> Note: You might need to restart PhpStorm and make sure `.phpstorm.meta.php` is indexed.
|
> Note: You might need to restart PhpStorm and make sure `.phpstorm.meta.php` is indexed.
|
||||||
> Note: When you receive a FatalException about a class that is not found, check your config (for example, remove S3 as cloud driver when you don't have S3 configured. Remove Redis ServiceProvider when you don't use it).
|
> Note: When you receive a FatalException about a class that is not found, check your config (for example, remove S3 as cloud driver when you don't have S3 configured. Remove Redis ServiceProvider when you don't use it).
|
||||||
|
|
||||||
|
## Lumen Install
|
||||||
|
|
||||||
|
This package is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a barebone version of Laravel and the main configuration parameters are instead located in `bootstrap/app.php`, some alterations must be made.
|
||||||
|
|
||||||
|
#### Enabling Facades
|
||||||
|
|
||||||
|
While Laravel IDE Helper can generate automatically default Facades for code hinting, Lumen doesn't come with Facades activated. If you plan in using them, you must enable them under the `Create The Application` section, uncommenting this line:
|
||||||
|
|
||||||
|
```php
|
||||||
|
// $app->withFacades();
|
||||||
|
```
|
||||||
|
|
||||||
|
From there, you should be able to use the `create_alias()` function to add additional Facades into your application.
|
||||||
|
|
||||||
|
#### Adding the Service Provider
|
||||||
|
|
||||||
|
You can install Laravel IDE Helper in `app/Providers/AppServiceProvider.php`, and uncommenting this line that registers the App Service Providers so it can properly load.
|
||||||
|
|
||||||
|
```php
|
||||||
|
// $app->register(App\Providers\AppServiceProvider::class);
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are not using that line, that is usually handy to manage gracefully multiple Laravel/Lumen installations, you will have to add this line of code under the `Register Service Providers` section of your `bootstrap/app.php`.
|
||||||
|
|
||||||
|
```php
|
||||||
|
if ($app->environment() !== 'production') {
|
||||||
|
$app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
After that, Laravel IDE Helper should work correctly. During the generation process, the script may throw exceptions saying that some Class(s) doesn't exist or there are some undefined indexes. This is normal, as Lumen has some default packages stripped away, like Cookies, Storage and Session. If you plan to add these packages, you will have to add them manually and create additional Facades if needed.
|
||||||
|
|
||||||
|
#### Adding Additional Facades
|
||||||
|
|
||||||
|
Currently Lumen IDE Helper doesn't take into account additional Facades created under `bootstrap/app.php` using `create_alias()`, so you need to create a `config/app.php` file and add your custom aliases under an `aliases` array again, like so:
|
||||||
|
|
||||||
|
```php
|
||||||
|
return [
|
||||||
|
'aliases' => [
|
||||||
|
'CustomAliasOne' => Example\Support\Facades\CustomAliasOne::class,
|
||||||
|
'CustomAliasTwo' => Example\Support\Facades\CustomAliasTwo::class,
|
||||||
|
//...
|
||||||
|
]
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
After you run ```php artisan ide-helper:generate```, it's recommended (but not mandatory) to rename `config/app.php` to something else until you have to re-generate the docs or after passing to production enviroment. Lumen 5.1+ will read this file for configuration parameters if it is present, and may overlap some configurations if it is completely populated.
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
The Laravel IDE Helper Generator is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
The Laravel IDE Helper Generator is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
|
||||||
|
[ico-version]: https://img.shields.io/packagist/v/barryvdh/laravel-ide-helper.svg?style=flat-square
|
||||||
|
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
||||||
|
[ico-travis]: https://img.shields.io/travis/barryvdh/laravel-ide-helper/master.svg?style=flat-square
|
||||||
|
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/barryvdh/laravel-ide-helper.svg?style=flat-square
|
||||||
|
[ico-code-quality]: https://img.shields.io/scrutinizer/g/barryvdh/laravel-ide-helper.svg?style=flat-square
|
||||||
|
[ico-downloads]: https://img.shields.io/packagist/dt/barryvdh/laravel-ide-helper.svg?style=flat-square
|
||||||
|
|
||||||
|
[link-packagist]: https://packagist.org/packages/barryvdh/laravel-ide-helper
|
||||||
|
[link-travis]: https://travis-ci.org/barryvdh/laravel-ide-helper
|
||||||
|
[link-scrutinizer]: https://scrutinizer-ci.com/g/barryvdh/laravel-ide-helper/code-structure
|
||||||
|
[link-code-quality]: https://scrutinizer-ci.com/g/barryvdh/laravel-ide-helper
|
||||||
|
[link-downloads]: https://packagist.org/packages/barryvdh/laravel-ide-helper
|
||||||
|
[link-author]: https://github.com/barryvdh
|
||||||
|
[link-contributors]: ../../contributors
|
||||||
|
|||||||
+66
-15
@@ -7,33 +7,84 @@
|
|||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
* @see https://github.com/barryvdh/laravel-ide-helper
|
* @see https://github.com/barryvdh/laravel-ide-helper
|
||||||
*/
|
*/
|
||||||
|
namespace {
|
||||||
<?php foreach($namespaces as $namespace => $aliases): ?>
|
|
||||||
namespace <?= $namespace == '__root' ? '' : $namespace ?>{
|
|
||||||
<?php if($namespace == '__root'): ?>
|
|
||||||
exit("This file should not be included, only analyzed by your IDE");
|
exit("This file should not be included, only analyzed by your IDE");
|
||||||
<?= $helpers ?>
|
}
|
||||||
<?php endif; ?>
|
|
||||||
|
<?php foreach($namespaces_by_extends_ns as $namespace => $aliases): ?>
|
||||||
|
<?php if ($namespace == '\Illuminate\Database\Eloquent'): continue; endif; ?>
|
||||||
|
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||||
<?php foreach($aliases as $alias): ?>
|
<?php foreach($aliases as $alias): ?>
|
||||||
|
|
||||||
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> <?= $alias->getExtends() ? 'extends ' . $alias->getExtends() : '' ?>{
|
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
|
||||||
<?php foreach($alias->getMethods() as $method): ?>
|
<?php foreach($alias->getMethods() as $method): ?>
|
||||||
|
|
||||||
<?= trim($method->getDocComment(' ')) ?>
|
<?= trim($method->getDocComment(' ')) ?>
|
||||||
|
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
||||||
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>){<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
{<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
||||||
|
|
||||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
||||||
}
|
}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
<?php endforeach; ?>
|
||||||
<?php endforeach; ?>
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?php foreach($namespaces_by_alias_ns as $namespace => $aliases): ?>
|
||||||
|
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||||
|
<?php foreach($aliases as $alias): ?>
|
||||||
|
|
||||||
|
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {<?php if ($alias->getExtendsNamespace() == '\Illuminate\Database\Eloquent'): ?>
|
||||||
|
<?php foreach($alias->getMethods() as $method): ?>
|
||||||
|
<?= trim($method->getDocComment(' ')) ?>
|
||||||
|
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
||||||
|
{<?php if($method->getDeclaringClass() !== $method->getRoot()): ?>
|
||||||
|
|
||||||
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
||||||
|
}
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>}
|
||||||
|
<?php endforeach; ?>
|
||||||
|
}
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?php if($helpers): ?>
|
||||||
|
namespace {
|
||||||
|
<?= $helpers ?>
|
||||||
|
}
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if($include_fluent): ?>
|
||||||
|
namespace Illuminate\Support {
|
||||||
|
/**
|
||||||
|
* Methods commonly used in migrations
|
||||||
|
*
|
||||||
|
* @method Fluent after(string $column) Add the after modifier
|
||||||
|
* @method Fluent charset(string $charset) Add the character set modifier
|
||||||
|
* @method Fluent collation(string $collation) Add the collation modifier
|
||||||
|
* @method Fluent comment(string $comment) Add comment
|
||||||
|
* @method Fluent default(mixed $value) Add the default modifier
|
||||||
|
* @method Fluent first() Select first row
|
||||||
|
* @method Fluent index(string $name = null) Add the in dex clause
|
||||||
|
* @method Fluent on(string $table) `on` of a foreign key
|
||||||
|
* @method Fluent onDelete(string $action) `on delete` of a foreign key
|
||||||
|
* @method Fluent onUpdate(string $action) `on update` of a foreign key
|
||||||
|
* @method Fluent primary() Add the primary key modifier
|
||||||
|
* @method Fluent references(string $column) `references` of a foreign key
|
||||||
|
* @method Fluent nullable() Add the nullable modifier
|
||||||
|
* @method Fluent unique(string $name = null) Add unique index clause
|
||||||
|
* @method Fluent unsigned() Add the unsigned modifier
|
||||||
|
* @method Fluent useCurrent() Add the default timestamp value
|
||||||
|
*/
|
||||||
|
class Fluent {}
|
||||||
|
}
|
||||||
|
<?php endif ?>
|
||||||
|
|||||||
@@ -9,13 +9,42 @@ namespace PHPSTORM_META {
|
|||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
* @see https://github.com/barryvdh/laravel-ide-helper
|
* @see https://github.com/barryvdh/laravel-ide-helper
|
||||||
*/
|
*/
|
||||||
$STATIC_METHOD_TYPES = [
|
<?php foreach ($methods as $method): ?>
|
||||||
<?php foreach($methods as $method): ?>
|
override(<?= $method ?>, map([
|
||||||
<?= $method ?> => [
|
'' => '@',
|
||||||
'' == '@',
|
|
||||||
<?php foreach($bindings as $abstract => $class): ?>
|
<?php foreach($bindings as $abstract => $class): ?>
|
||||||
'<?= $abstract ?>' instanceof \<?= $class ?>,
|
'<?= $abstract ?>' => \<?= $class ?>::class,
|
||||||
<?php endforeach ?> ],
|
<?php endforeach; ?>
|
||||||
<?php endforeach ?>
|
]));
|
||||||
];
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
override(\Illuminate\Support\Arr::add(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::except(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::first(0), elementType(0));
|
||||||
|
override(\Illuminate\Support\Arr::last(0), elementType(0));
|
||||||
|
override(\Illuminate\Support\Arr::get(0), elementType(0));
|
||||||
|
override(\Illuminate\Support\Arr::only(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::prepend(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::pull(0), elementType(0));
|
||||||
|
override(\Illuminate\Support\Arr::set(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::shuffle(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::sort(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::sortRecursive(0), type(0));
|
||||||
|
override(\Illuminate\Support\Arr::where(0), type(0));
|
||||||
|
override(\array_add(0), type(0));
|
||||||
|
override(\array_except(0), type(0));
|
||||||
|
override(\array_first(0), elementType(0));
|
||||||
|
override(\array_last(0), elementType(0));
|
||||||
|
override(\array_get(0), elementType(0));
|
||||||
|
override(\array_only(0), type(0));
|
||||||
|
override(\array_prepend(0), type(0));
|
||||||
|
override(\array_pull(0), elementType(0));
|
||||||
|
override(\array_set(0), type(0));
|
||||||
|
override(\array_sort(0), type(0));
|
||||||
|
override(\array_sort_recursive(0), type(0));
|
||||||
|
override(\array_where(0), type(0));
|
||||||
|
override(\head(0), elementType(0));
|
||||||
|
override(\last(0), elementType(0));
|
||||||
|
override(\with(0), type(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+346
-284
@@ -1,284 +1,346 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
* @link https://github.com/barryvdh/laravel-ide-helper
|
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
class Alias
|
class Alias
|
||||||
{
|
{
|
||||||
protected $alias;
|
protected $alias;
|
||||||
protected $facade;
|
protected $facade;
|
||||||
protected $extends = null;
|
protected $extends = null;
|
||||||
protected $classType = 'class';
|
protected $extendsClass = null;
|
||||||
protected $short;
|
protected $extendsNamespace = null;
|
||||||
protected $namespace = '__root';
|
protected $classType = 'class';
|
||||||
protected $root = null;
|
protected $short;
|
||||||
protected $classes = array();
|
protected $namespace = '__root';
|
||||||
protected $methods = array();
|
protected $root = null;
|
||||||
protected $usedMethods = array();
|
protected $classes = array();
|
||||||
protected $valid = false;
|
protected $methods = array();
|
||||||
protected $magicMethods = array();
|
protected $usedMethods = array();
|
||||||
protected $interfaces = array();
|
protected $valid = false;
|
||||||
|
protected $magicMethods = array();
|
||||||
/**
|
protected $interfaces = array();
|
||||||
* @param string $alias
|
|
||||||
* @param string $facade
|
/**
|
||||||
* @param array $magicMethods
|
* @param string $alias
|
||||||
* @param array $interfaces
|
* @param string $facade
|
||||||
*/
|
* @param array $magicMethods
|
||||||
public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array())
|
* @param array $interfaces
|
||||||
{
|
*/
|
||||||
$this->alias = $alias;
|
public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array())
|
||||||
$this->magicMethods = $magicMethods;
|
{
|
||||||
$this->interfaces = $interfaces;
|
$this->alias = $alias;
|
||||||
|
$this->magicMethods = $magicMethods;
|
||||||
// Make the class absolute
|
$this->interfaces = $interfaces;
|
||||||
$facade = '\\' . ltrim($facade, '\\');
|
|
||||||
$this->facade = $facade;
|
// Make the class absolute
|
||||||
|
$facade = '\\' . ltrim($facade, '\\');
|
||||||
$this->detectRoot();
|
$this->facade = $facade;
|
||||||
|
|
||||||
if ((!$this->isTrait() && $this->root)) {
|
$this->detectRoot();
|
||||||
$this->valid = true;
|
|
||||||
} else {
|
if ((!$this->isTrait() && $this->root)) {
|
||||||
return;
|
$this->valid = true;
|
||||||
}
|
} else {
|
||||||
|
return;
|
||||||
$this->addClass($this->root);
|
}
|
||||||
$this->detectNamespace();
|
|
||||||
$this->detectClassType();
|
$this->addClass($this->root);
|
||||||
|
$this->detectNamespace();
|
||||||
if($facade === '\Illuminate\Database\Eloquent\Model'){
|
$this->detectClassType();
|
||||||
$this->usedMethods = array('decrement', 'increment');
|
$this->detectExtendsNamespace();
|
||||||
}
|
|
||||||
}
|
if ($facade === '\Illuminate\Database\Eloquent\Model') {
|
||||||
|
$this->usedMethods = array('decrement', 'increment');
|
||||||
/**
|
}
|
||||||
* Add one or more classes to analyze
|
}
|
||||||
*
|
|
||||||
* @param array|string $classes
|
/**
|
||||||
*/
|
* Add one or more classes to analyze
|
||||||
public function addClass($classes)
|
*
|
||||||
{
|
* @param array|string $classes
|
||||||
$classes = (array)$classes;
|
*/
|
||||||
foreach ($classes as $class) {
|
public function addClass($classes)
|
||||||
if (class_exists($class) || interface_exists($class)) {
|
{
|
||||||
$this->classes[] = $class;
|
$classes = (array)$classes;
|
||||||
}else{
|
foreach ($classes as $class) {
|
||||||
echo "Class not exists: $class\r\n";
|
if (class_exists($class) || interface_exists($class)) {
|
||||||
}
|
$this->classes[] = $class;
|
||||||
}
|
} else {
|
||||||
}
|
echo "Class not exists: $class\r\n";
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Check if this class is valid to process.
|
}
|
||||||
* @return bool
|
|
||||||
*/
|
/**
|
||||||
public function isValid()
|
* Check if this class is valid to process.
|
||||||
{
|
* @return bool
|
||||||
return $this->valid;
|
*/
|
||||||
}
|
public function isValid()
|
||||||
|
{
|
||||||
/**
|
return $this->valid;
|
||||||
* Get the classtype, 'interface' or 'class'
|
}
|
||||||
*
|
|
||||||
* @return string
|
/**
|
||||||
*/
|
* Get the classtype, 'interface' or 'class'
|
||||||
public function getClasstype()
|
*
|
||||||
{
|
* @return string
|
||||||
return $this->classType;
|
*/
|
||||||
}
|
public function getClasstype()
|
||||||
|
{
|
||||||
/**
|
return $this->classType;
|
||||||
* Get the class which this alias extends
|
}
|
||||||
*
|
|
||||||
* @return null|string
|
/**
|
||||||
*/
|
* Get the class which this alias extends
|
||||||
public function getExtends()
|
*
|
||||||
{
|
* @return null|string
|
||||||
return $this->extends;
|
*/
|
||||||
}
|
public function getExtends()
|
||||||
|
{
|
||||||
/**
|
return $this->extends;
|
||||||
* Get the Alias by which this class is called
|
}
|
||||||
*
|
|
||||||
* @return string
|
/**
|
||||||
*/
|
* Get the class short name which this alias extends
|
||||||
public function getAlias()
|
*
|
||||||
{
|
* @return null|string
|
||||||
return $this->alias;
|
*/
|
||||||
}
|
public function getExtendsClass()
|
||||||
|
{
|
||||||
/**
|
return $this->extendsClass;
|
||||||
* Return the short name (without namespace)
|
}
|
||||||
*/
|
|
||||||
public function getShortName(){
|
/**
|
||||||
return $this->short;
|
* Get the namespace of the class which this alias extends
|
||||||
}
|
*
|
||||||
/**
|
* @return null|string
|
||||||
* Get the namespace from the alias
|
*/
|
||||||
*
|
public function getExtendsNamespace()
|
||||||
* @return string
|
{
|
||||||
*/
|
return $this->extendsNamespace;
|
||||||
public function getNamespace()
|
}
|
||||||
{
|
|
||||||
return $this->namespace;
|
/**
|
||||||
}
|
* Get the Alias by which this class is called
|
||||||
|
*
|
||||||
/**
|
* @return string
|
||||||
* Get the methods found by this Alias
|
*/
|
||||||
*
|
public function getAlias()
|
||||||
* @return array
|
{
|
||||||
*/
|
return $this->alias;
|
||||||
public function getMethods()
|
}
|
||||||
{
|
|
||||||
$this->addMagicMethods();
|
/**
|
||||||
$this->detectMethods();
|
* Return the short name (without namespace)
|
||||||
return $this->methods;
|
*/
|
||||||
}
|
public function getShortName()
|
||||||
|
{
|
||||||
/**
|
return $this->short;
|
||||||
* Detect the namespace
|
}
|
||||||
*/
|
/**
|
||||||
protected function detectNamespace()
|
* Get the namespace from the alias
|
||||||
{
|
*
|
||||||
if (strpos($this->alias, '\\')) {
|
* @return string
|
||||||
$nsParts = explode('\\', $this->alias);
|
*/
|
||||||
$this->short = array_pop($nsParts);
|
public function getNamespace()
|
||||||
$this->namespace = implode('\\', $nsParts);
|
{
|
||||||
}else{
|
return $this->namespace;
|
||||||
$this->short = $this->alias;
|
}
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* Get the methods found by this Alias
|
||||||
/**
|
*
|
||||||
* Detect the class type
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function detectClassType()
|
public function getMethods()
|
||||||
{
|
{
|
||||||
//Some classes extend the facade
|
$this->addMagicMethods();
|
||||||
if (interface_exists($this->facade)) {
|
$this->detectMethods();
|
||||||
$this->classType = 'interface';
|
return $this->methods;
|
||||||
$this->extends = $this->facade;
|
}
|
||||||
} else {
|
|
||||||
$this->classType = 'class';
|
/**
|
||||||
if (class_exists($this->facade)) {
|
* Detect the namespace
|
||||||
$this->extends = $this->facade;
|
*/
|
||||||
}
|
protected function detectNamespace()
|
||||||
}
|
{
|
||||||
}
|
if (strpos($this->alias, '\\')) {
|
||||||
|
$nsParts = explode('\\', $this->alias);
|
||||||
/**
|
$this->short = array_pop($nsParts);
|
||||||
* Get the real root of a facade
|
$this->namespace = implode('\\', $nsParts);
|
||||||
*
|
} else {
|
||||||
* @return bool|string
|
$this->short = $this->alias;
|
||||||
*/
|
}
|
||||||
protected function detectRoot()
|
}
|
||||||
{
|
|
||||||
$facade = $this->facade;
|
/**
|
||||||
|
* Detect the extends namespace
|
||||||
try {
|
*/
|
||||||
//If possible, get the facade root
|
protected function detectExtendsNamespace()
|
||||||
if (method_exists($facade, 'getFacadeRoot')) {
|
{
|
||||||
$root = get_class($facade::getFacadeRoot());
|
if (strpos($this->extends, '\\') !== false) {
|
||||||
} else {
|
$nsParts = explode('\\', $this->extends);
|
||||||
$root = $facade;
|
$this->extendsClass = array_pop($nsParts);
|
||||||
}
|
$this->extendsNamespace = implode('\\', $nsParts);
|
||||||
|
}
|
||||||
//If it doesn't exist, skip it
|
}
|
||||||
if (!class_exists($root) && !interface_exists($root)) {
|
|
||||||
return;
|
/**
|
||||||
}
|
* Detect the class type
|
||||||
|
*/
|
||||||
$this->root = $root;
|
protected function detectClassType()
|
||||||
|
{
|
||||||
//When the database connection is not set, some classes will be skipped
|
//Some classes extend the facade
|
||||||
} catch (\PDOException $e) {
|
if (interface_exists($this->facade)) {
|
||||||
$this->error(
|
$this->classType = 'interface';
|
||||||
"PDOException: " . $e->getMessage() . "\nPlease configure your database connection correctly, or use the sqlite memory driver (-M). Skipping $facade."
|
$this->extends = $this->facade;
|
||||||
);
|
} else {
|
||||||
} catch (\Exception $e) {
|
$this->classType = 'class';
|
||||||
$this->error("Exception: " . $e->getMessage() . "\nSkipping $facade.");
|
if (class_exists($this->facade)) {
|
||||||
}
|
$this->extends = $this->facade;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Detect if this class is a trait or not.
|
|
||||||
*
|
/**
|
||||||
* @return bool
|
* Get the real root of a facade
|
||||||
*/
|
*
|
||||||
protected function isTrait()
|
* @return bool|string
|
||||||
{
|
*/
|
||||||
// Check if the facade is not a Trait
|
protected function detectRoot()
|
||||||
if (function_exists('trait_exists') && trait_exists($this->facade)) {
|
{
|
||||||
return true;
|
$facade = $this->facade;
|
||||||
}
|
|
||||||
return false;
|
try {
|
||||||
}
|
//If possible, get the facade root
|
||||||
|
if (method_exists($facade, 'getFacadeRoot')) {
|
||||||
/**
|
$root = get_class($facade::getFacadeRoot());
|
||||||
* Add magic methods, as defined in the configuration files
|
} else {
|
||||||
*/
|
$root = $facade;
|
||||||
protected function addMagicMethods()
|
}
|
||||||
{
|
|
||||||
foreach($this->magicMethods as $magic => $real){
|
//If it doesn't exist, skip it
|
||||||
list($className, $name) = explode('::', $real);
|
if (!class_exists($root) && !interface_exists($root)) {
|
||||||
if(!class_exists($className) && !interface_exists($className)){
|
return;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
$method = new \ReflectionMethod($className, $name);
|
$this->root = $root;
|
||||||
$class = new \ReflectionClass($className);
|
|
||||||
|
//When the database connection is not set, some classes will be skipped
|
||||||
if(!in_array($method->name, $this->usedMethods)){
|
} catch (\PDOException $e) {
|
||||||
if($class !== $this->root){
|
$this->error(
|
||||||
$this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces);
|
"PDOException: " . $e->getMessage() .
|
||||||
}
|
"\nPlease configure your database connection correctly, or use the sqlite memory driver (-M)." .
|
||||||
$this->usedMethods[] = $magic;
|
" Skipping $facade."
|
||||||
}
|
);
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
}
|
$this->error("Exception: " . $e->getMessage() . "\nSkipping $facade.");
|
||||||
|
}
|
||||||
/**
|
}
|
||||||
* Get the methods for one or multiple classes.
|
|
||||||
*
|
/**
|
||||||
* @return string
|
* Detect if this class is a trait or not.
|
||||||
*/
|
*
|
||||||
protected function detectMethods()
|
* @return bool
|
||||||
{
|
*/
|
||||||
|
protected function isTrait()
|
||||||
foreach ($this->classes as $class) {
|
{
|
||||||
$reflection = new \ReflectionClass($class);
|
// Check if the facade is not a Trait
|
||||||
|
if (function_exists('trait_exists') && trait_exists($this->facade)) {
|
||||||
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
return true;
|
||||||
if ($methods) {
|
}
|
||||||
foreach ($methods as $method) {
|
return false;
|
||||||
if (!in_array($method->name, $this->usedMethods)) {
|
}
|
||||||
// Only add the methods to the output when the root is not the same as the class.
|
|
||||||
// And don't add the __*() methods
|
/**
|
||||||
if ($this->extends !== $class && substr($method->name, 0, 2) !== '__') {
|
* Add magic methods, as defined in the configuration files
|
||||||
$this->methods[] = new Method($method, $this->alias, $reflection, $method->name, $this->interfaces);
|
*/
|
||||||
}
|
protected function addMagicMethods()
|
||||||
$this->usedMethods[] = $method->name;
|
{
|
||||||
}
|
foreach ($this->magicMethods as $magic => $real) {
|
||||||
}
|
list($className, $name) = explode('::', $real);
|
||||||
}
|
if (!class_exists($className) && !interface_exists($className)) {
|
||||||
}
|
continue;
|
||||||
}
|
}
|
||||||
|
$method = new \ReflectionMethod($className, $name);
|
||||||
/**
|
$class = new \ReflectionClass($className);
|
||||||
* Output an error.
|
|
||||||
*
|
if (!in_array($method->name, $this->usedMethods)) {
|
||||||
* @param string $string
|
if ($class !== $this->root) {
|
||||||
* @return void
|
$this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces);
|
||||||
*/
|
}
|
||||||
protected function error($string)
|
$this->usedMethods[] = $magic;
|
||||||
{
|
}
|
||||||
echo $string . "\r\n";
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Get the methods for one or multiple classes.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function detectMethods()
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach ($this->classes as $class) {
|
||||||
|
$reflection = new \ReflectionClass($class);
|
||||||
|
|
||||||
|
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||||
|
if ($methods) {
|
||||||
|
foreach ($methods as $method) {
|
||||||
|
if (!in_array($method->name, $this->usedMethods)) {
|
||||||
|
// Only add the methods to the output when the root is not the same as the class.
|
||||||
|
// And don't add the __*() methods
|
||||||
|
if ($this->extends !== $class && substr($method->name, 0, 2) !== '__') {
|
||||||
|
$this->methods[] = new Method(
|
||||||
|
$method,
|
||||||
|
$this->alias,
|
||||||
|
$reflection,
|
||||||
|
$method->name,
|
||||||
|
$this->interfaces
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$this->usedMethods[] = $method->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the class is macroable
|
||||||
|
$traits = collect($reflection->getTraitNames());
|
||||||
|
if ($traits->contains('Illuminate\Support\Traits\Macroable')) {
|
||||||
|
$properties = $reflection->getStaticProperties();
|
||||||
|
$macros = isset($properties['macros']) ? $properties['macros'] : [];
|
||||||
|
foreach ($macros as $macro_name => $macro_func) {
|
||||||
|
$function = new \ReflectionFunction($macro_func);
|
||||||
|
// Add macros
|
||||||
|
$this->methods[] = new Macro(
|
||||||
|
$function,
|
||||||
|
$this->alias,
|
||||||
|
$reflection,
|
||||||
|
$macro_name,
|
||||||
|
$this->interfaces
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output an error.
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function error($string)
|
||||||
|
{
|
||||||
|
echo $string . "\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ use Illuminate\Filesystem\Filesystem;
|
|||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A command to generate autocomplete information for your IDE
|
* A command to generate autocomplete information for your IDE
|
||||||
*
|
*
|
||||||
@@ -60,7 +59,8 @@ class GeneratorCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/*ConfigRepository */ $config,
|
/*ConfigRepository */ $config,
|
||||||
Filesystem $files, /* Illuminate\View\Factory */
|
Filesystem $files,
|
||||||
|
/* Illuminate\View\Factory */
|
||||||
$view
|
$view
|
||||||
) {
|
) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
@@ -74,7 +74,7 @@ class GeneratorCommand extends Command
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fire()
|
public function handle()
|
||||||
{
|
{
|
||||||
if (file_exists(base_path() . '/vendor/compiled.php') ||
|
if (file_exists(base_path() . '/vendor/compiled.php') ||
|
||||||
file_exists(base_path() . '/bootstrap/cache/compiled.php') ||
|
file_exists(base_path() . '/bootstrap/cache/compiled.php') ||
|
||||||
@@ -166,5 +166,4 @@ class GeneratorCommand extends Command
|
|||||||
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
|
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-12
@@ -19,7 +19,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
*
|
*
|
||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
*/
|
*/
|
||||||
class MetaCommand extends Command {
|
class MetaCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command name.
|
* The console command name.
|
||||||
@@ -41,12 +42,15 @@ class MetaCommand extends Command {
|
|||||||
|
|
||||||
/** @var \Illuminate\Contracts\View\Factory */
|
/** @var \Illuminate\Contracts\View\Factory */
|
||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
protected $methods = [
|
protected $methods = [
|
||||||
'new \Illuminate\Contracts\Container\Container',
|
'new \Illuminate\Contracts\Container\Container',
|
||||||
'\Illuminate\Contracts\Container\Container::make(\'\')',
|
'\Illuminate\Contracts\Container\Container::make(0)',
|
||||||
'\App::make(\'\')',
|
'\Illuminate\Contracts\Container\Container::makeWith(0)',
|
||||||
'app(\'\')',
|
'\App::make(0)',
|
||||||
|
'\App::makeWith(0)',
|
||||||
|
'\app(0)',
|
||||||
|
'\resolve(0)',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +58,8 @@ class MetaCommand extends Command {
|
|||||||
* @param \Illuminate\Contracts\Filesystem\Filesystem $files
|
* @param \Illuminate\Contracts\Filesystem\Filesystem $files
|
||||||
* @param \Illuminate\Contracts\View\Factory $view
|
* @param \Illuminate\Contracts\View\Factory $view
|
||||||
*/
|
*/
|
||||||
public function __construct($files, $view) {
|
public function __construct($files, $view)
|
||||||
|
{
|
||||||
$this->files = $files;
|
$this->files = $files;
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
@@ -65,7 +70,7 @@ class MetaCommand extends Command {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fire()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->registerClassAutoloadExceptions();
|
$this->registerClassAutoloadExceptions();
|
||||||
|
|
||||||
@@ -75,20 +80,20 @@ class MetaCommand extends Command {
|
|||||||
if (in_array($abstract, ['validator', 'seeder'])) {
|
if (in_array($abstract, ['validator', 'seeder'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$concrete = $this->laravel->make($abstract);
|
$concrete = $this->laravel->make($abstract);
|
||||||
if (is_object($concrete)) {
|
if (is_object($concrete)) {
|
||||||
$bindings[$abstract] = get_class($concrete);
|
$bindings[$abstract] = get_class($concrete);
|
||||||
}
|
}
|
||||||
}catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
||||||
$this->comment("Cannot make '$abstract': ".$e->getMessage());
|
$this->comment("Cannot make '$abstract': ".$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$content = $this->view->make('ide-helper::meta', [
|
$content = $this->view->make('meta', [
|
||||||
'bindings' => $bindings,
|
'bindings' => $bindings,
|
||||||
'methods' => $this->methods,
|
'methods' => $this->methods,
|
||||||
])->render();
|
])->render();
|
||||||
@@ -105,13 +110,13 @@ class MetaCommand extends Command {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of abstracts from the Laravel Application.
|
* Get a list of abstracts from the Laravel Application.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getAbstracts()
|
protected function getAbstracts()
|
||||||
{
|
{
|
||||||
$abstracts = $this->laravel->getBindings();
|
$abstracts = $this->laravel->getBindings();
|
||||||
|
|
||||||
// Return the abstract names only
|
// Return the abstract names only
|
||||||
return array_keys($abstracts);
|
return array_keys($abstracts);
|
||||||
}
|
}
|
||||||
|
|||||||
+241
-42
@@ -18,10 +18,10 @@ use Symfony\Component\Console\Input\InputOption;
|
|||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||||
use phpDocumentor\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use phpDocumentor\Reflection\DocBlock\Context;
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A command to generate autocomplete information for your IDE
|
* A command to generate autocomplete information for your IDE
|
||||||
@@ -50,11 +50,16 @@ class ModelsCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Generate autocompletion for models';
|
protected $description = 'Generate autocompletion for models';
|
||||||
|
|
||||||
|
protected $write_model_magic_where;
|
||||||
protected $properties = array();
|
protected $properties = array();
|
||||||
protected $methods = array();
|
protected $methods = array();
|
||||||
protected $write = false;
|
protected $write = false;
|
||||||
protected $dirs = array();
|
protected $dirs = array();
|
||||||
protected $reset;
|
protected $reset;
|
||||||
|
/**
|
||||||
|
* @var bool[string]
|
||||||
|
*/
|
||||||
|
protected $nullableColumns = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Filesystem $files
|
* @param Filesystem $files
|
||||||
@@ -70,22 +75,23 @@ class ModelsCommand extends Command
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function fire()
|
public function handle()
|
||||||
{
|
{
|
||||||
$filename = $this->option('filename');
|
$filename = $this->option('filename');
|
||||||
$this->write = $this->option('write');
|
$this->write = $this->option('write');
|
||||||
$this->dirs = array_merge(
|
$this->dirs = array_merge(
|
||||||
$this->laravel['config']->get('ide-helper.model_locations'),
|
$this->laravel['config']->get('ide-helper.model_locations'),
|
||||||
$this->option('dir')
|
$this->option('dir')
|
||||||
);
|
);
|
||||||
$model = $this->argument('model');
|
$model = $this->argument('model');
|
||||||
$ignore = $this->option('ignore');
|
$ignore = $this->option('ignore');
|
||||||
$this->reset = $this->option('reset');
|
$this->reset = $this->option('reset');
|
||||||
|
$this->write_model_magic_where = $this->laravel['config']->get('ide-helper.write_model_magic_where', true);
|
||||||
|
|
||||||
//If filename is default and Write is not specified, ask what to do
|
//If filename is default and Write is not specified, ask what to do
|
||||||
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
||||||
if ($this->confirm(
|
if ($this->confirm(
|
||||||
"Do you want to overwrite the existing model files? Choose no to write to $filename instead? (Yes/No): "
|
"Do you want to overwrite the existing model files? Choose no to write to $filename instead? (Yes/No): "
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
$this->write = true;
|
$this->write = true;
|
||||||
@@ -140,7 +146,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$output = "<?php
|
$output = "<?php
|
||||||
/**
|
/**
|
||||||
* An helper file for your Eloquent Models
|
* A helper file for your Eloquent Models
|
||||||
* Copy the phpDocs from this file to the correct Model,
|
* Copy the phpDocs from this file to the correct Model,
|
||||||
* And remove them from this file, to prevent double declarations.
|
* And remove them from this file, to prevent double declarations.
|
||||||
*
|
*
|
||||||
@@ -175,7 +181,8 @@ class ModelsCommand extends Command
|
|||||||
// handle abstract classes, interfaces, ...
|
// handle abstract classes, interfaces, ...
|
||||||
$reflectionClass = new \ReflectionClass($name);
|
$reflectionClass = new \ReflectionClass($name);
|
||||||
|
|
||||||
if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
|
if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')
|
||||||
|
|| $reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Relations\Pivot')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +191,8 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$reflectionClass->IsInstantiable()) {
|
if (!$reflectionClass->IsInstantiable()) {
|
||||||
throw new \Exception($name . ' is not instantiable.');
|
// ignore abstract class or interface
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$model = $this->laravel->make($name);
|
$model = $this->laravel->make($name);
|
||||||
@@ -193,24 +201,29 @@ class ModelsCommand extends Command
|
|||||||
$this->getPropertiesFromTable($model);
|
$this->getPropertiesFromTable($model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (method_exists($model, 'getCasts')) {
|
||||||
|
$this->castPropertiesType($model);
|
||||||
|
}
|
||||||
|
|
||||||
$this->getPropertiesFromMethods($model);
|
$this->getPropertiesFromMethods($model);
|
||||||
$output .= $this->createPhpDocs($name);
|
$this->getSoftDeleteMethods($model);
|
||||||
$ignore[] = $name;
|
$output .= $this->createPhpDocs($name);
|
||||||
|
$ignore[] = $name;
|
||||||
|
$this->nullableColumns = [];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$hasDoctrine) {
|
if (!$hasDoctrine) {
|
||||||
$this->error(
|
$this->error(
|
||||||
'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. Please require that in your composer.json and run `composer update`.'
|
'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. '.
|
||||||
|
'Please require that in your composer.json and run `composer update`.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -228,6 +241,73 @@ class ModelsCommand extends Command
|
|||||||
return $models;
|
return $models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cast the properties's type from $casts.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*/
|
||||||
|
protected function castPropertiesType($model)
|
||||||
|
{
|
||||||
|
$casts = $model->getCasts();
|
||||||
|
foreach ($casts as $name => $type) {
|
||||||
|
switch ($type) {
|
||||||
|
case 'boolean':
|
||||||
|
case 'bool':
|
||||||
|
$realType = 'boolean';
|
||||||
|
break;
|
||||||
|
case 'string':
|
||||||
|
$realType = 'string';
|
||||||
|
break;
|
||||||
|
case 'array':
|
||||||
|
case 'json':
|
||||||
|
$realType = 'array';
|
||||||
|
break;
|
||||||
|
case 'object':
|
||||||
|
$realType = 'object';
|
||||||
|
break;
|
||||||
|
case 'int':
|
||||||
|
case 'integer':
|
||||||
|
case 'timestamp':
|
||||||
|
$realType = 'integer';
|
||||||
|
break;
|
||||||
|
case 'real':
|
||||||
|
case 'double':
|
||||||
|
case 'float':
|
||||||
|
$realType = 'float';
|
||||||
|
break;
|
||||||
|
case 'date':
|
||||||
|
case 'datetime':
|
||||||
|
$realType = '\Carbon\Carbon';
|
||||||
|
break;
|
||||||
|
case 'collection':
|
||||||
|
$realType = '\Illuminate\Support\Collection';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$realType = 'mixed';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->properties[$name])) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
$this->properties[$name]['type'] = $this->getTypeOverride($realType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the overide type for the give type.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getTypeOverride($type)
|
||||||
|
{
|
||||||
|
$typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', array());
|
||||||
|
|
||||||
|
return isset($typeOverrides[$type]) ? $typeOverrides[$type] : $type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the properties from the database table.
|
* Load the properties from the database table.
|
||||||
*
|
*
|
||||||
@@ -275,13 +355,21 @@ class ModelsCommand extends Command
|
|||||||
case 'smallint':
|
case 'smallint':
|
||||||
$type = 'integer';
|
$type = 'integer';
|
||||||
break;
|
break;
|
||||||
|
case 'boolean':
|
||||||
|
switch (config('database.default')) {
|
||||||
|
case 'sqlite':
|
||||||
|
case 'mysql':
|
||||||
|
$type = 'integer';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$type = 'boolean';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'decimal':
|
case 'decimal':
|
||||||
case 'float':
|
case 'float':
|
||||||
$type = 'float';
|
$type = 'float';
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
|
||||||
$type = 'boolean';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
$type = 'mixed';
|
$type = 'mixed';
|
||||||
break;
|
break;
|
||||||
@@ -289,7 +377,17 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
$comment = $column->getComment();
|
$comment = $column->getComment();
|
||||||
$this->setProperty($name, $type, true, true, $comment);
|
if (!$column->getNotnull()) {
|
||||||
|
$this->nullableColumns[$name] = true;
|
||||||
|
}
|
||||||
|
$this->setProperty($name, $type, true, true, $comment, !$column->getNotnull());
|
||||||
|
if ($this->write_model_magic_where) {
|
||||||
|
$this->setMethod(
|
||||||
|
Str::camel("where_" . $name),
|
||||||
|
'\Illuminate\Database\Eloquent\Builder|\\' . get_class($model),
|
||||||
|
array('$value')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,21 +399,24 @@ class ModelsCommand extends Command
|
|||||||
{
|
{
|
||||||
$methods = get_class_methods($model);
|
$methods = get_class_methods($model);
|
||||||
if ($methods) {
|
if ($methods) {
|
||||||
|
sort($methods);
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
if (Str::startsWith($method, 'get') && Str::endsWith(
|
if (Str::startsWith($method, 'get') && Str::endsWith(
|
||||||
$method,
|
$method,
|
||||||
'Attribute'
|
'Attribute'
|
||||||
) && $method !== 'getAttribute'
|
) && $method !== 'getAttribute'
|
||||||
) {
|
) {
|
||||||
//Magic get<name>Attribute
|
//Magic get<name>Attribute
|
||||||
$name = Str::snake(substr($method, 3, -9));
|
$name = Str::snake(substr($method, 3, -9));
|
||||||
if (!empty($name)) {
|
if (!empty($name)) {
|
||||||
$this->setProperty($name, null, true, null);
|
$reflection = new \ReflectionMethod($model, $method);
|
||||||
|
$type = $this->getReturnTypeFromDocBlock($reflection);
|
||||||
|
$this->setProperty($name, $type, true, null);
|
||||||
}
|
}
|
||||||
} elseif (Str::startsWith($method, 'set') && Str::endsWith(
|
} elseif (Str::startsWith($method, 'set') && Str::endsWith(
|
||||||
$method,
|
$method,
|
||||||
'Attribute'
|
'Attribute'
|
||||||
) && $method !== 'setAttribute'
|
) && $method !== 'setAttribute'
|
||||||
) {
|
) {
|
||||||
//Magic set<name>Attribute
|
//Magic set<name>Attribute
|
||||||
$name = Str::snake(substr($method, 3, -9));
|
$name = Str::snake(substr($method, 3, -9));
|
||||||
@@ -330,10 +431,11 @@ class ModelsCommand extends Command
|
|||||||
$args = $this->getParameters($reflection);
|
$args = $this->getParameters($reflection);
|
||||||
//Remove the first ($query) argument
|
//Remove the first ($query) argument
|
||||||
array_shift($args);
|
array_shift($args);
|
||||||
$this->setMethod($name, '\Illuminate\Database\Query\Builder|\\' . $reflection->class, $args);
|
$this->setMethod($name, '\Illuminate\Database\Eloquent\Builder|\\' . $reflection->class, $args);
|
||||||
}
|
}
|
||||||
} elseif (!method_exists('Eloquent', $method) && !Str::startsWith($method, 'get')) {
|
} elseif (!method_exists('Illuminate\Database\Eloquent\Model', $method)
|
||||||
|
&& !Str::startsWith($method, 'get')
|
||||||
|
) {
|
||||||
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
||||||
$reflection = new \ReflectionMethod($model, $method);
|
$reflection = new \ReflectionMethod($model, $method);
|
||||||
|
|
||||||
@@ -351,33 +453,50 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
foreach (array(
|
foreach (array(
|
||||||
'hasMany',
|
'hasMany',
|
||||||
|
'hasManyThrough',
|
||||||
'belongsToMany',
|
'belongsToMany',
|
||||||
'hasOne',
|
'hasOne',
|
||||||
'belongsTo',
|
'belongsTo',
|
||||||
|
'morphOne',
|
||||||
'morphTo',
|
'morphTo',
|
||||||
'morphMany',
|
'morphMany',
|
||||||
'morphToMany'
|
'morphToMany'
|
||||||
) as $relation) {
|
) as $relation) {
|
||||||
$search = '$this->' . $relation . '(';
|
$search = '$this->' . $relation . '(';
|
||||||
if ($pos = stripos($code, $search)) {
|
if ($pos = stripos($code, $search)) {
|
||||||
|
|
||||||
//Resolve the relation's model to a Relation object.
|
//Resolve the relation's model to a Relation object.
|
||||||
$relationObj = $model->$method();
|
$relationObj = $model->$method();
|
||||||
|
|
||||||
if ($relationObj instanceof Relation) {
|
if ($relationObj instanceof Relation) {
|
||||||
$relatedModel = '\\' . get_class($relationObj->getRelated());
|
$relatedModel = '\\' . get_class($relationObj->getRelated());
|
||||||
|
|
||||||
if (in_array($relation, ['belongsToMany', 'hasMany', 'morphMany', 'morphToMany'])) {
|
$relations = ['hasManyThrough', 'belongsToMany', 'hasMany', 'morphMany', 'morphToMany'];
|
||||||
|
if (in_array($relation, $relations)) {
|
||||||
//Collection or array of models (because Collection is Arrayable)
|
//Collection or array of models (because Collection is Arrayable)
|
||||||
$this->setProperty(
|
$this->setProperty(
|
||||||
$method,
|
$method,
|
||||||
$this->getCollectionClass($relatedModel) . '|' . $relatedModel . '[]',
|
$this->getCollectionClass($relatedModel) . '|' . $relatedModel . '[]',
|
||||||
true,
|
true,
|
||||||
null
|
null
|
||||||
|
);
|
||||||
|
} elseif ($relation === "morphTo") {
|
||||||
|
// Model isn't specified because relation is polymorphic
|
||||||
|
$this->setProperty(
|
||||||
|
$method,
|
||||||
|
'\Illuminate\Database\Eloquent\Model|\Eloquent',
|
||||||
|
true,
|
||||||
|
null
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
//Single model is returned
|
//Single model is returned
|
||||||
$this->setProperty($method, $relatedModel, true, null);
|
$this->setProperty(
|
||||||
|
$method,
|
||||||
|
$relatedModel,
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
'',
|
||||||
|
$this->isRelationForeignKeyNullable($relationObj)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,13 +507,33 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* Check if the foreign key of the relation is nullable
|
||||||
* @param string|null $type
|
*
|
||||||
* @param bool|null $read
|
* @param Relation $relation
|
||||||
* @param bool|null $write
|
*
|
||||||
* @param string|null $comment
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function setProperty($name, $type = null, $read = null, $write = null, $comment='')
|
private function isRelationForeignKeyNullable(Relation $relation)
|
||||||
|
{
|
||||||
|
$reflectionObj = new \ReflectionObject($relation);
|
||||||
|
if (!$reflectionObj->hasProperty('foreignKey')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$fkProp = $reflectionObj->getProperty('foreignKey');
|
||||||
|
$fkProp->setAccessible(true);
|
||||||
|
|
||||||
|
return isset($this->nullableColumns[$fkProp->getValue($relation)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param string|null $type
|
||||||
|
* @param bool|null $read
|
||||||
|
* @param bool|null $write
|
||||||
|
* @param string|null $comment
|
||||||
|
* @param bool $nullable
|
||||||
|
*/
|
||||||
|
protected function setProperty($name, $type = null, $read = null, $write = null, $comment = '', $nullable = false)
|
||||||
{
|
{
|
||||||
if (!isset($this->properties[$name])) {
|
if (!isset($this->properties[$name])) {
|
||||||
$this->properties[$name] = array();
|
$this->properties[$name] = array();
|
||||||
@@ -404,7 +543,11 @@ class ModelsCommand extends Command
|
|||||||
$this->properties[$name]['comment'] = (string) $comment;
|
$this->properties[$name]['comment'] = (string) $comment;
|
||||||
}
|
}
|
||||||
if ($type !== null) {
|
if ($type !== null) {
|
||||||
$this->properties[$name]['type'] = $type;
|
$newType = $this->getTypeOverride($type);
|
||||||
|
if ($nullable) {
|
||||||
|
$newType .='|null';
|
||||||
|
}
|
||||||
|
$this->properties[$name]['type'] = $newType;
|
||||||
}
|
}
|
||||||
if ($read !== null) {
|
if ($read !== null) {
|
||||||
$this->properties[$name]['read'] = $read;
|
$this->properties[$name]['read'] = $read;
|
||||||
@@ -470,11 +613,18 @@ class ModelsCommand extends Command
|
|||||||
} else {
|
} else {
|
||||||
$attr = 'property-read';
|
$attr = 'property-read';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->hasCamelCaseModelProperties()) {
|
||||||
|
$name = Str::camel($name);
|
||||||
|
}
|
||||||
|
|
||||||
$tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}");
|
$tagLine = trim("@{$attr} {$property['type']} {$name} {$property['comment']}");
|
||||||
$tag = Tag::createInstance($tagLine, $phpdoc);
|
$tag = Tag::createInstance($tagLine, $phpdoc);
|
||||||
$phpdoc->appendTag($tag);
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($this->methods);
|
||||||
|
|
||||||
foreach ($this->methods as $name => $method) {
|
foreach ($this->methods as $name => $method) {
|
||||||
if (in_array($name, $methods)) {
|
if (in_array($name, $methods)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -484,6 +634,10 @@ class ModelsCommand extends Command
|
|||||||
$phpdoc->appendTag($tag);
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->write && ! $phpdoc->getTagsByName('mixin')) {
|
||||||
|
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
|
||||||
|
}
|
||||||
|
|
||||||
$serializer = new DocBlockSerializer();
|
$serializer = new DocBlockSerializer();
|
||||||
$serializer->getDocComment($phpdoc);
|
$serializer->getDocComment($phpdoc);
|
||||||
$docComment = $serializer->getDocComment($phpdoc);
|
$docComment = $serializer->getDocComment($phpdoc);
|
||||||
@@ -507,7 +661,7 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} {}\n}\n\n";
|
$output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} extends \Eloquent {}\n}\n\n";
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +678,8 @@ class ModelsCommand extends Command
|
|||||||
$paramsWithDefault = array();
|
$paramsWithDefault = array();
|
||||||
/** @var \ReflectionParameter $param */
|
/** @var \ReflectionParameter $param */
|
||||||
foreach ($method->getParameters() as $param) {
|
foreach ($method->getParameters() as $param) {
|
||||||
$paramStr = '$' . $param->getName();
|
$paramClass = $param->getClass();
|
||||||
|
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
|
||||||
$params[] = $paramStr;
|
$params[] = $paramStr;
|
||||||
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
|
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
|
||||||
$default = $param->getDefaultValue();
|
$default = $param->getDefaultValue();
|
||||||
@@ -565,4 +720,48 @@ class ModelsCommand extends Command
|
|||||||
$model = new $className;
|
$model = new $className;
|
||||||
return '\\' . get_class($model->newCollection());
|
return '\\' . get_class($model->newCollection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function hasCamelCaseModelProperties()
|
||||||
|
{
|
||||||
|
return $this->laravel['config']->get('ide-helper.model_camel_case_properties', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get method return type based on it DocBlock comment
|
||||||
|
*
|
||||||
|
* @param \ReflectionMethod $reflection
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
protected function getReturnTypeFromDocBlock(\ReflectionMethod $reflection)
|
||||||
|
{
|
||||||
|
$type = null;
|
||||||
|
$phpdoc = new DocBlock($reflection);
|
||||||
|
|
||||||
|
if ($phpdoc->hasTag('return')) {
|
||||||
|
$type = $phpdoc->getTagsByName('return')[0]->getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates methods provided by the SoftDeletes trait
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
*/
|
||||||
|
protected function getSoftDeleteMethods($model)
|
||||||
|
{
|
||||||
|
$traits = class_uses(get_class($model), true);
|
||||||
|
if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', $traits)) {
|
||||||
|
$this->setMethod('forceDelete', 'bool|null', []);
|
||||||
|
$this->setMethod('restore', 'bool|null', []);
|
||||||
|
|
||||||
|
$this->setMethod('withTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||||
|
$this->setMethod('withoutTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||||
|
$this->setMethod('onlyTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+323
-277
@@ -1,277 +1,323 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
* @link https://github.com/barryvdh/laravel-ide-helper
|
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Illuminate\Foundation\AliasLoader;
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\AliasLoader;
|
||||||
use Illuminate\Config\Repository as ConfigRepository;
|
use Illuminate\Support\Collection;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use ReflectionClass;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
class Generator
|
|
||||||
{
|
class Generator
|
||||||
/** @var \Illuminate\Config\Repository */
|
{
|
||||||
protected $config;
|
/** @var \Illuminate\Config\Repository */
|
||||||
|
protected $config;
|
||||||
/** @var \Illuminate\View\Factory */
|
|
||||||
protected $view;
|
/** @var \Illuminate\View\Factory */
|
||||||
|
protected $view;
|
||||||
/** @var \Symfony\Component\Console\Output\OutputInterface */
|
|
||||||
protected $output;
|
/** @var \Symfony\Component\Console\Output\OutputInterface */
|
||||||
|
protected $output;
|
||||||
protected $extra = array();
|
|
||||||
protected $magic = array();
|
protected $extra = array();
|
||||||
protected $interfaces = array();
|
protected $magic = array();
|
||||||
protected $helpers;
|
protected $interfaces = array();
|
||||||
|
protected $helpers;
|
||||||
/**
|
|
||||||
* @param \Illuminate\Config\Repository $config
|
/**
|
||||||
* @param \Illuminate\View\Factory $view
|
* @param \Illuminate\Config\Repository $config
|
||||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
* @param \Illuminate\View\Factory $view
|
||||||
* @param string $helpers
|
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||||
*/
|
* @param string $helpers
|
||||||
public function __construct(/*ConfigRepository */ $config,
|
*/
|
||||||
/* Illuminate\View\Factory */ $view,
|
public function __construct(
|
||||||
OutputInterface $output = null,
|
/*ConfigRepository */ $config,
|
||||||
$helpers = ''
|
/* Illuminate\View\Factory */ $view,
|
||||||
) {
|
OutputInterface $output = null,
|
||||||
$this->config = $config;
|
$helpers = ''
|
||||||
$this->view = $view;
|
) {
|
||||||
|
$this->config = $config;
|
||||||
// Find the drivers to add to the extra/interfaces
|
$this->view = $view;
|
||||||
$this->detectDrivers();
|
|
||||||
|
// Find the drivers to add to the extra/interfaces
|
||||||
$this->extra = array_merge($this->extra, $this->config->get('ide-helper.extra'));
|
$this->detectDrivers();
|
||||||
$this->magic = array_merge($this->magic, $this->config->get('ide-helper.magic'));
|
|
||||||
$this->interfaces = array_merge($this->interfaces, $this->config->get('ide-helper.interfaces'));
|
$this->extra = array_merge($this->extra, $this->config->get('ide-helper.extra'));
|
||||||
// Make all interface classes absolute
|
$this->magic = array_merge($this->magic, $this->config->get('ide-helper.magic'));
|
||||||
foreach ($this->interfaces as &$interface) {
|
$this->interfaces = array_merge($this->interfaces, $this->config->get('ide-helper.interfaces'));
|
||||||
$interface = '\\' . ltrim($interface, '\\');
|
// Make all interface classes absolute
|
||||||
}
|
foreach ($this->interfaces as &$interface) {
|
||||||
$this->helpers = $helpers;
|
$interface = '\\' . ltrim($interface, '\\');
|
||||||
}
|
}
|
||||||
|
$this->helpers = $helpers;
|
||||||
/**
|
}
|
||||||
* Generate the helper file contents;
|
|
||||||
*
|
/**
|
||||||
* @param string $format The format to generate the helper in (php/json)
|
* Generate the helper file contents;
|
||||||
* @return string;
|
*
|
||||||
*/
|
* @param string $format The format to generate the helper in (php/json)
|
||||||
public function generate($format = 'php')
|
* @return string;
|
||||||
{
|
*/
|
||||||
// Check if the generator for this format exists
|
public function generate($format = 'php')
|
||||||
$method = 'generate'.ucfirst($format).'Helper';
|
{
|
||||||
if (method_exists($this, $method)) {
|
// Check if the generator for this format exists
|
||||||
return $this->$method();
|
$method = 'generate'.ucfirst($format).'Helper';
|
||||||
}
|
if (method_exists($this, $method)) {
|
||||||
|
return $this->$method();
|
||||||
return $this->generatePhpHelper();
|
}
|
||||||
}
|
|
||||||
|
return $this->generatePhpHelper();
|
||||||
public function generatePhpHelper()
|
}
|
||||||
{
|
|
||||||
$app = app();
|
public function generatePhpHelper()
|
||||||
return $this->view->make('ide-helper::helper')
|
{
|
||||||
->with('namespaces', $this->getNamespaces())
|
$app = app();
|
||||||
->with('helpers', $this->helpers)
|
return $this->view->make('helper')
|
||||||
->with('version', $app->version())
|
->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace())
|
||||||
->render();
|
->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace())
|
||||||
}
|
->with('helpers', $this->helpers)
|
||||||
|
->with('version', $app->version())
|
||||||
public function generateJsonHelper()
|
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
||||||
{
|
->render();
|
||||||
$classes = array();
|
}
|
||||||
foreach ($this->getNamespaces() as $aliases) {
|
|
||||||
foreach($aliases as $alias) {
|
public function generateJsonHelper()
|
||||||
$functions = array();
|
{
|
||||||
foreach ($alias->getMethods() as $method) {
|
$classes = array();
|
||||||
$functions[$method->getName()] = '('. $method->getParamsWithDefault().')';
|
foreach ($this->getValidAliases() as $aliases) {
|
||||||
}
|
foreach ($aliases as $alias) {
|
||||||
$classes[$alias->getAlias()] = array(
|
$functions = array();
|
||||||
'functions' => $functions,
|
foreach ($alias->getMethods() as $method) {
|
||||||
);
|
$functions[$method->getName()] = '('. $method->getParamsWithDefault().')';
|
||||||
}
|
}
|
||||||
}
|
$classes[$alias->getAlias()] = array(
|
||||||
|
'functions' => $functions,
|
||||||
$flags = JSON_FORCE_OBJECT;
|
);
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
}
|
||||||
$flags |= JSON_PRETTY_PRINT;
|
}
|
||||||
}
|
|
||||||
|
$flags = JSON_FORCE_OBJECT;
|
||||||
return json_encode(array(
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
'php' => array(
|
$flags |= JSON_PRETTY_PRINT;
|
||||||
'classes' => $classes,
|
}
|
||||||
),
|
|
||||||
), $flags);
|
return json_encode(array(
|
||||||
}
|
'php' => array(
|
||||||
|
'classes' => $classes,
|
||||||
protected function detectDrivers()
|
),
|
||||||
{
|
), $flags);
|
||||||
$this->interfaces['\Illuminate\Contracts\Auth\Authenticatable'] = config('auth.model', 'App\User');
|
}
|
||||||
|
|
||||||
try{
|
protected function detectDrivers()
|
||||||
if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)) {
|
{
|
||||||
$authMethod = version_compare(Application::VERSION, '5.2', '>=') ? 'guard' : 'driver';
|
$defaultUserModel = config('auth.providers.users.model', config('auth.model', 'App\User'));
|
||||||
$class = get_class(\Auth::$authMethod());
|
$this->interfaces['\Illuminate\Contracts\Auth\Authenticatable'] = $defaultUserModel;
|
||||||
$this->extra['Auth'] = array($class);
|
|
||||||
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
|
try {
|
||||||
}
|
if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)) {
|
||||||
}catch (\Exception $e) {}
|
if (class_exists('\Illuminate\Foundation\Application')) {
|
||||||
|
$authMethod = version_compare(Application::VERSION, '5.2', '>=') ? 'guard' : 'driver';
|
||||||
try{
|
} else {
|
||||||
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
|
$refClass = new ReflectionClass('\Laravel\Lumen\Application');
|
||||||
$class = get_class(\DB::connection());
|
$versionStr = $refClass->newInstanceWithoutConstructor()->version();
|
||||||
$this->extra['DB'] = array($class);
|
$authMethod = strpos($versionStr, 'Lumen (5.0') === 0 ?
|
||||||
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
|
'driver' :
|
||||||
}
|
(strpos($versionStr, 'Lumen (5.1') === 0 ? 'driver' : 'guard');
|
||||||
}catch (\Exception $e) {}
|
}
|
||||||
|
$class = get_class(\Auth::$authMethod());
|
||||||
try{
|
$this->extra['Auth'] = array($class);
|
||||||
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
|
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
|
||||||
$driver = get_class(\Cache::driver());
|
}
|
||||||
$store = get_class(\Cache::getStore());
|
} catch (\Exception $e) {
|
||||||
$this->extra['Cache'] = array($driver, $store);
|
}
|
||||||
$this->interfaces['\Illuminate\Cache\StoreInterface'] = $store;
|
|
||||||
}
|
try {
|
||||||
}catch (\Exception $e) {}
|
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
|
||||||
|
$class = get_class(\DB::connection());
|
||||||
try{
|
$this->extra['DB'] = array($class);
|
||||||
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
|
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
|
||||||
$class = get_class(\Queue::connection());
|
}
|
||||||
$this->extra['Queue'] = array($class);
|
} catch (\Exception $e) {
|
||||||
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
|
}
|
||||||
}
|
|
||||||
}catch (\Exception $e) {}
|
try {
|
||||||
|
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
|
||||||
try{
|
$driver = get_class(\Cache::driver());
|
||||||
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)){
|
$store = get_class(\Cache::getStore());
|
||||||
$class = get_class(\SSH::connection());
|
$this->extra['Cache'] = array($driver, $store);
|
||||||
$this->extra['SSH'] = array($class);
|
$this->interfaces['\Illuminate\Cache\StoreInterface'] = $store;
|
||||||
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
|
}
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
}catch (\Exception $e) {}
|
}
|
||||||
|
|
||||||
}
|
try {
|
||||||
|
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
|
||||||
/**
|
$class = get_class(\Queue::connection());
|
||||||
* Find all namespaces/aliases that are valid for us to render
|
$this->extra['Queue'] = array($class);
|
||||||
*
|
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
|
||||||
* @return array
|
}
|
||||||
*/
|
} catch (\Exception $e) {
|
||||||
protected function getNamespaces()
|
}
|
||||||
{
|
|
||||||
$namespaces = array();
|
try {
|
||||||
|
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)) {
|
||||||
// Get all aliases
|
$class = get_class(\SSH::connection());
|
||||||
foreach ($this->getAliases() as $name => $facade) {
|
$this->extra['SSH'] = array($class);
|
||||||
// Skip the Redis facade, if not available (otherwise Fatal PHP Error)
|
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
|
||||||
if ($facade == 'Illuminate\Support\Facades\Redis' && !class_exists('Predis\Client')) {
|
}
|
||||||
continue;
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
|
try {
|
||||||
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
|
if (class_exists('Storage') && is_a('Storage', '\Illuminate\Support\Facades\Storage', true)) {
|
||||||
if ($alias->isValid()) {
|
$class = get_class(\Storage::disk());
|
||||||
|
$this->extra['Storage'] = array($class);
|
||||||
//Add extra methods, from other classes (magic static calls)
|
$this->interfaces['\Illuminate\Contracts\Filesystem\Filesystem'] = $class;
|
||||||
if (array_key_exists($name, $this->extra)) {
|
}
|
||||||
$alias->addClass($this->extra[$name]);
|
} catch (\Exception $e) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$namespace = $alias->getNamespace();
|
|
||||||
if (!isset($namespaces[$namespace])) {
|
/**
|
||||||
$namespaces[$namespace] = array();
|
* Find all aliases that are valid for us to render
|
||||||
}
|
*
|
||||||
$namespaces[$namespace][] = $alias;
|
* @return Collection
|
||||||
}
|
*/
|
||||||
|
protected function getValidAliases()
|
||||||
}
|
{
|
||||||
|
$aliases = new Collection();
|
||||||
return $namespaces;
|
|
||||||
}
|
// Get all aliases
|
||||||
|
foreach ($this->getAliases() as $name => $facade) {
|
||||||
protected function getAliases()
|
// Skip the Redis facade, if not available (otherwise Fatal PHP Error)
|
||||||
{
|
if ($facade == 'Illuminate\Support\Facades\Redis' && !class_exists('Predis\Client')) {
|
||||||
// For Laravel, use the AliasLoader
|
continue;
|
||||||
if (class_exists('Illuminate\Foundation\AliasLoader')) {
|
}
|
||||||
return AliasLoader::getInstance()->getAliases();
|
|
||||||
}
|
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
|
||||||
|
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
|
||||||
$facades = [
|
if ($alias->isValid()) {
|
||||||
'App' => 'Illuminate\Support\Facades\App',
|
//Add extra methods, from other classes (magic static calls)
|
||||||
'Auth' => 'Illuminate\Support\Facades\Auth',
|
if (array_key_exists($name, $this->extra)) {
|
||||||
'Bus' => 'Illuminate\Support\Facades\Bus',
|
$alias->addClass($this->extra[$name]);
|
||||||
'DB' => 'Illuminate\Support\Facades\DB',
|
}
|
||||||
'Cache' => 'Illuminate\Support\Facades\Cache',
|
|
||||||
'Cookie' => 'Illuminate\Support\Facades\Cookie',
|
$aliases[] = $alias;
|
||||||
'Crypt' => 'Illuminate\Support\Facades\Crypt',
|
}
|
||||||
'Event' => 'Illuminate\Support\Facades\Event',
|
}
|
||||||
'Hash' => 'Illuminate\Support\Facades\Hash',
|
|
||||||
'Log' => 'Illuminate\Support\Facades\Log',
|
return $aliases;
|
||||||
'Mail' => 'Illuminate\Support\Facades\Mail',
|
}
|
||||||
'Queue' => 'Illuminate\Support\Facades\Queue',
|
|
||||||
'Request' => 'Illuminate\Support\Facades\Request',
|
/**
|
||||||
'Schema' => 'Illuminate\Support\Facades\Schema',
|
* Regroup aliases by namespace of extended classes
|
||||||
'Session' => 'Illuminate\Support\Facades\Session',
|
*
|
||||||
'Storage' => 'Illuminate\Support\Facades\Storage',
|
* @return Collection
|
||||||
//'Validator' => 'Illuminate\Support\Facades\Validator',
|
*/
|
||||||
];
|
protected function getAliasesByExtendsNamespace()
|
||||||
|
{
|
||||||
// Only return the ones that actually exist
|
return $this->getValidAliases()->groupBy(function (Alias $alias) {
|
||||||
return array_filter($facades, function($alias){
|
return $alias->getExtendsNamespace();
|
||||||
return class_exists($alias);
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Regroup aliases by namespace of alias
|
||||||
* Get the driver/connection/store from the managers
|
*
|
||||||
*
|
* @return Collection
|
||||||
* @param $alias
|
*/
|
||||||
* @return array|bool|string
|
protected function getAliasesByAliasNamespace()
|
||||||
*/
|
{
|
||||||
public function getDriver($alias)
|
return $this->getValidAliases()->groupBy(function (Alias $alias) {
|
||||||
{
|
return $alias->getNamespace();
|
||||||
try {
|
});
|
||||||
if ($alias == "Auth") {
|
}
|
||||||
$driver = \Auth::driver();
|
|
||||||
} elseif ($alias == "DB") {
|
protected function getAliases()
|
||||||
$driver = \DB::connection();
|
{
|
||||||
} elseif ($alias == "Cache") {
|
// For Laravel, use the AliasLoader
|
||||||
$driver = get_class(\Cache::driver());
|
if (class_exists('Illuminate\Foundation\AliasLoader')) {
|
||||||
$store = get_class(\Cache::getStore());
|
return AliasLoader::getInstance()->getAliases();
|
||||||
return array($driver, $store);
|
}
|
||||||
} elseif ($alias == "Queue") {
|
|
||||||
$driver = \Queue::connection();
|
$facades = [
|
||||||
} else {
|
'App' => 'Illuminate\Support\Facades\App',
|
||||||
return false;
|
'Auth' => 'Illuminate\Support\Facades\Auth',
|
||||||
}
|
'Bus' => 'Illuminate\Support\Facades\Bus',
|
||||||
|
'DB' => 'Illuminate\Support\Facades\DB',
|
||||||
return get_class($driver);
|
'Cache' => 'Illuminate\Support\Facades\Cache',
|
||||||
} catch (\Exception $e) {
|
'Cookie' => 'Illuminate\Support\Facades\Cookie',
|
||||||
$this->error("Could not determine driver/connection for $alias.");
|
'Crypt' => 'Illuminate\Support\Facades\Crypt',
|
||||||
return false;
|
'Event' => 'Illuminate\Support\Facades\Event',
|
||||||
}
|
'Hash' => 'Illuminate\Support\Facades\Hash',
|
||||||
}
|
'Log' => 'Illuminate\Support\Facades\Log',
|
||||||
|
'Mail' => 'Illuminate\Support\Facades\Mail',
|
||||||
/**
|
'Queue' => 'Illuminate\Support\Facades\Queue',
|
||||||
* Write a string as error output.
|
'Request' => 'Illuminate\Support\Facades\Request',
|
||||||
*
|
'Schema' => 'Illuminate\Support\Facades\Schema',
|
||||||
* @param string $string
|
'Session' => 'Illuminate\Support\Facades\Session',
|
||||||
* @return void
|
'Storage' => 'Illuminate\Support\Facades\Storage',
|
||||||
*/
|
//'Validator' => 'Illuminate\Support\Facades\Validator',
|
||||||
protected function error($string)
|
];
|
||||||
{
|
|
||||||
if($this->output){
|
$facades = array_merge($facades, $this->config->get('app.aliases', []));
|
||||||
$this->output->writeln("<error>$string</error>");
|
|
||||||
}else{
|
// Only return the ones that actually exist
|
||||||
echo $string . "\r\n";
|
return array_filter($facades, function ($alias) {
|
||||||
}
|
return class_exists($alias);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the driver/connection/store from the managers
|
||||||
|
*
|
||||||
|
* @param $alias
|
||||||
|
* @return array|bool|string
|
||||||
|
*/
|
||||||
|
public function getDriver($alias)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if ($alias == "Auth") {
|
||||||
|
$driver = \Auth::driver();
|
||||||
|
} elseif ($alias == "DB") {
|
||||||
|
$driver = \DB::connection();
|
||||||
|
} elseif ($alias == "Cache") {
|
||||||
|
$driver = get_class(\Cache::driver());
|
||||||
|
$store = get_class(\Cache::getStore());
|
||||||
|
return array($driver, $store);
|
||||||
|
} elseif ($alias == "Queue") {
|
||||||
|
$driver = \Queue::connection();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return get_class($driver);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error("Could not determine driver/connection for $alias.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a string as error output.
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function error($string)
|
||||||
|
{
|
||||||
|
if ($this->output) {
|
||||||
|
$this->output->writeln("<error>$string</error>");
|
||||||
|
} else {
|
||||||
|
echo $string . "\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ use Illuminate\Support\ServiceProvider;
|
|||||||
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||||
|
use Illuminate\View\Engines\EngineResolver;
|
||||||
|
use Illuminate\View\Engines\PhpEngine;
|
||||||
|
use Illuminate\View\Factory;
|
||||||
|
use Illuminate\View\FileViewFinder;
|
||||||
|
|
||||||
class IdeHelperServiceProvider extends ServiceProvider
|
class IdeHelperServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -53,23 +57,27 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||||
$this->mergeConfigFrom($configPath, 'ide-helper');
|
$this->mergeConfigFrom($configPath, 'ide-helper');
|
||||||
|
$localViewFactory = $this->createLocalViewFactory();
|
||||||
|
|
||||||
$this->app['command.ide-helper.generate'] = $this->app->share(
|
$this->app->singleton(
|
||||||
function ($app) {
|
'command.ide-helper.generate',
|
||||||
return new GeneratorCommand($app['config'], $app['files'], $app['view']);
|
function ($app) use ($localViewFactory) {
|
||||||
|
return new GeneratorCommand($app['config'], $app['files'], $localViewFactory);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app['command.ide-helper.models'] = $this->app->share(
|
$this->app->singleton(
|
||||||
|
'command.ide-helper.models',
|
||||||
function ($app) {
|
function ($app) {
|
||||||
return new ModelsCommand($app['files']);
|
return new ModelsCommand($app['files']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->app['command.ide-helper.meta'] = $this->app->share(
|
$this->app->singleton(
|
||||||
function ($app) {
|
'command.ide-helper.meta',
|
||||||
return new MetaCommand($app['files'], $app['view']);
|
function ($app) use ($localViewFactory) {
|
||||||
}
|
return new MetaCommand($app['files'], $localViewFactory);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
$this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta');
|
||||||
@@ -85,4 +93,19 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
return array('command.ide-helper.generate', 'command.ide-helper.models');
|
return array('command.ide-helper.generate', 'command.ide-helper.models');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Factory
|
||||||
|
*/
|
||||||
|
private function createLocalViewFactory()
|
||||||
|
{
|
||||||
|
$resolver = new EngineResolver();
|
||||||
|
$resolver->register('php', function () {
|
||||||
|
return new PhpEngine();
|
||||||
|
});
|
||||||
|
$finder = new FileViewFinder($this->app['files'], [__DIR__ . '/../resources/views']);
|
||||||
|
$factory = new Factory($resolver, $finder, $this->app['events']);
|
||||||
|
$factory->addExtension('php', 'php');
|
||||||
|
|
||||||
|
return $factory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
|
use Barryvdh\Reflection\DocBlock;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
|
|
||||||
|
class Macro extends Method
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Macro constructor.
|
||||||
|
*
|
||||||
|
* @param \ReflectionFunction $method
|
||||||
|
* @param string $alias
|
||||||
|
* @param \ReflectionClass $class
|
||||||
|
* @param null $methodName
|
||||||
|
* @param array $interfaces
|
||||||
|
*/
|
||||||
|
public function __construct(\ReflectionFunction $method, $alias, $class, $methodName = null, $interfaces = array())
|
||||||
|
{
|
||||||
|
$this->method = $method;
|
||||||
|
$this->interfaces = $interfaces;
|
||||||
|
$this->name = $methodName ?: $method->name;
|
||||||
|
$this->namespace = $class->getNamespaceName();
|
||||||
|
|
||||||
|
//Create a DocBlock and serializer instance
|
||||||
|
$this->phpdoc = new DocBlock($method);
|
||||||
|
|
||||||
|
//Normalize the description and inherit the docs from parents/interfaces
|
||||||
|
try {
|
||||||
|
$this->normalizeParams($this->phpdoc);
|
||||||
|
$this->normalizeReturn($this->phpdoc);
|
||||||
|
$this->normalizeDescription($this->phpdoc);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the parameters, including formatted default values
|
||||||
|
$this->getParameters($method);
|
||||||
|
|
||||||
|
//Make the method static
|
||||||
|
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
|
||||||
|
|
||||||
|
//Reference the 'real' function in the declaringclass
|
||||||
|
$this->declaringClassName = '\\' . ltrim($class->name, '\\');
|
||||||
|
$this->root = '\\' . ltrim($class->getName(), '\\');
|
||||||
|
}
|
||||||
|
}
|
||||||
+314
-313
@@ -1,313 +1,314 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
* @author Barry vd. Heuvel <[email protected]>
|
* @author Barry vd. Heuvel <[email protected]>
|
||||||
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
* @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl)
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
* @link https://github.com/barryvdh/laravel-ide-helper
|
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use phpDocumentor\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use phpDocumentor\Reflection\DocBlock\Context;
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
use Barryvdh\Reflection\DocBlock\Tag;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
|
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag\ParamTag;
|
use Barryvdh\Reflection\DocBlock\Tag\ParamTag;
|
||||||
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
|
|
||||||
class Method
|
class Method
|
||||||
{
|
{
|
||||||
/** @var \phpDocumentor\Reflection\DocBlock */
|
/** @var \Barryvdh\Reflection\DocBlock */
|
||||||
protected $phpdoc;
|
protected $phpdoc;
|
||||||
|
|
||||||
/** @var \ReflectionMethod */
|
/** @var \ReflectionMethod */
|
||||||
protected $method;
|
protected $method;
|
||||||
|
|
||||||
protected $output = '';
|
protected $output = '';
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $namespace;
|
protected $namespace;
|
||||||
protected $params = array();
|
protected $params = array();
|
||||||
protected $params_with_default = array();
|
protected $params_with_default = array();
|
||||||
protected $interfaces = array();
|
protected $interfaces = array();
|
||||||
protected $return = null;
|
protected $return = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \ReflectionMethod $method
|
* @param \ReflectionMethod $method
|
||||||
* @param string $alias
|
* @param string $alias
|
||||||
* @param string $class
|
* @param \ReflectionClass $class
|
||||||
* @param string|null $methodName
|
* @param string|null $methodName
|
||||||
* @param array $interfaces
|
* @param array $interfaces
|
||||||
*/
|
*/
|
||||||
public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array())
|
public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array())
|
||||||
{
|
{
|
||||||
$this->method = $method;
|
$this->method = $method;
|
||||||
$this->interfaces = $interfaces;
|
$this->interfaces = $interfaces;
|
||||||
$this->name = $methodName ?: $method->name;
|
$this->name = $methodName ?: $method->name;
|
||||||
$this->namespace = $method->getDeclaringClass()->getNamespaceName();
|
$this->namespace = $method->getDeclaringClass()->getNamespaceName();
|
||||||
|
|
||||||
//Create a DocBlock and serializer instance
|
//Create a DocBlock and serializer instance
|
||||||
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
|
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
|
||||||
|
|
||||||
//Normalize the description and inherit the docs from parents/interfaces
|
//Normalize the description and inherit the docs from parents/interfaces
|
||||||
try {
|
try {
|
||||||
$this->normalizeParams($this->phpdoc);
|
$this->normalizeParams($this->phpdoc);
|
||||||
$this->normalizeReturn($this->phpdoc);
|
$this->normalizeReturn($this->phpdoc);
|
||||||
$this->normalizeDescription($this->phpdoc);
|
$this->normalizeDescription($this->phpdoc);
|
||||||
} catch (\Exception $e) {}
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
//Get the parameters, including formatted default values
|
|
||||||
$this->getParameters($method);
|
//Get the parameters, including formatted default values
|
||||||
|
$this->getParameters($method);
|
||||||
//Make the method static
|
|
||||||
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
|
//Make the method static
|
||||||
|
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
|
||||||
//Reference the 'real' function in the declaringclass
|
|
||||||
$declaringClass = $method->getDeclaringClass();
|
//Reference the 'real' function in the declaringclass
|
||||||
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
|
$declaringClass = $method->getDeclaringClass();
|
||||||
$this->root = '\\' . ltrim($class->getName(), '\\');
|
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
|
||||||
}
|
$this->root = '\\' . ltrim($class->getName(), '\\');
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the class wherein the function resides
|
/**
|
||||||
*
|
* Get the class wherein the function resides
|
||||||
* @return string
|
*
|
||||||
*/
|
* @return string
|
||||||
public function getDeclaringClass()
|
*/
|
||||||
{
|
public function getDeclaringClass()
|
||||||
return $this->declaringClassName;
|
{
|
||||||
}
|
return $this->declaringClassName;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Return the class from which this function would be called
|
/**
|
||||||
*
|
* Return the class from which this function would be called
|
||||||
* @return string
|
*
|
||||||
*/
|
* @return string
|
||||||
public function getRoot()
|
*/
|
||||||
{
|
public function getRoot()
|
||||||
return $this->root;
|
{
|
||||||
}
|
return $this->root;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the docblock for this method
|
/**
|
||||||
*
|
* Get the docblock for this method
|
||||||
* @param string $prefix
|
*
|
||||||
* @return mixed
|
* @param string $prefix
|
||||||
*/
|
* @return mixed
|
||||||
public function getDocComment($prefix = "\t\t")
|
*/
|
||||||
{
|
public function getDocComment($prefix = "\t\t")
|
||||||
$serializer = new DocBlockSerializer(1, $prefix);
|
{
|
||||||
return $serializer->getDocComment($this->phpdoc);
|
$serializer = new DocBlockSerializer(1, $prefix);
|
||||||
}
|
return $serializer->getDocComment($this->phpdoc);
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the method name
|
/**
|
||||||
*
|
* Get the method name
|
||||||
* @return string
|
*
|
||||||
*/
|
* @return string
|
||||||
public function getName()
|
*/
|
||||||
{
|
public function getName()
|
||||||
return $this->name;
|
{
|
||||||
}
|
return $this->name;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the parameters for this method
|
/**
|
||||||
*
|
* Get the parameters for this method
|
||||||
* @param bool $implode Wether to implode the array or not
|
*
|
||||||
* @return string
|
* @param bool $implode Wether to implode the array or not
|
||||||
*/
|
* @return string
|
||||||
public function getParams($implode = true)
|
*/
|
||||||
{
|
public function getParams($implode = true)
|
||||||
return $implode ? implode(', ', $this->params) : $this->params;
|
{
|
||||||
}
|
return $implode ? implode(', ', $this->params) : $this->params;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the parameters for this method including default values
|
/**
|
||||||
*
|
* Get the parameters for this method including default values
|
||||||
* @param bool $implode Wether to implode the array or not
|
*
|
||||||
* @return string
|
* @param bool $implode Wether to implode the array or not
|
||||||
*/
|
* @return string
|
||||||
public function getParamsWithDefault($implode = true)
|
*/
|
||||||
{
|
public function getParamsWithDefault($implode = true)
|
||||||
return $implode ? implode(', ', $this->params_with_default) : $this->params_with_default;
|
{
|
||||||
}
|
return $implode ? implode(', ', $this->params_with_default) : $this->params_with_default;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the description and get the inherited docs.
|
/**
|
||||||
*
|
* Get the description and get the inherited docs.
|
||||||
* @param DocBlock $phpdoc
|
*
|
||||||
*/
|
* @param DocBlock $phpdoc
|
||||||
protected function normalizeDescription(DocBlock $phpdoc)
|
*/
|
||||||
{
|
protected function normalizeDescription(DocBlock $phpdoc)
|
||||||
//Get the short + long description from the DocBlock
|
{
|
||||||
$description = $phpdoc->getText();
|
//Get the short + long description from the DocBlock
|
||||||
|
$description = $phpdoc->getText();
|
||||||
//Loop through parents/interfaces, to fill in {@inheritdoc}
|
|
||||||
if (strpos($description, '{@inheritdoc}') !== false) {
|
//Loop through parents/interfaces, to fill in {@inheritdoc}
|
||||||
$inheritdoc = $this->getInheritDoc($this->method);
|
if (strpos($description, '{@inheritdoc}') !== false) {
|
||||||
$inheritDescription = $inheritdoc->getText();
|
$inheritdoc = $this->getInheritDoc($this->method);
|
||||||
|
$inheritDescription = $inheritdoc->getText();
|
||||||
$description = str_replace('{@inheritdoc}', $inheritDescription, $description);
|
|
||||||
$phpdoc->setText($description);
|
$description = str_replace('{@inheritdoc}', $inheritDescription, $description);
|
||||||
|
$phpdoc->setText($description);
|
||||||
$this->normalizeParams($inheritdoc);
|
|
||||||
$this->normalizeReturn($inheritdoc);
|
$this->normalizeParams($inheritdoc);
|
||||||
|
$this->normalizeReturn($inheritdoc);
|
||||||
//Add the tags that are inherited
|
|
||||||
$inheritTags = $inheritdoc->getTags();
|
//Add the tags that are inherited
|
||||||
if ($inheritTags) {
|
$inheritTags = $inheritdoc->getTags();
|
||||||
/** @var Tag $tag */
|
if ($inheritTags) {
|
||||||
foreach ($inheritTags as $tag) {
|
/** @var Tag $tag */
|
||||||
$tag->setDocBlock();
|
foreach ($inheritTags as $tag) {
|
||||||
$phpdoc->appendTag($tag);
|
$tag->setDocBlock();
|
||||||
}
|
$phpdoc->appendTag($tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Normalize the parameters
|
/**
|
||||||
*
|
* Normalize the parameters
|
||||||
* @param DocBlock $phpdoc
|
*
|
||||||
*/
|
* @param DocBlock $phpdoc
|
||||||
protected function normalizeParams(DocBlock $phpdoc)
|
*/
|
||||||
{
|
protected function normalizeParams(DocBlock $phpdoc)
|
||||||
//Get the return type and adjust them for beter autocomplete
|
{
|
||||||
$paramTags = $phpdoc->getTagsByName('param');
|
//Get the return type and adjust them for beter autocomplete
|
||||||
if ($paramTags) {
|
$paramTags = $phpdoc->getTagsByName('param');
|
||||||
/** @var ParamTag $tag */
|
if ($paramTags) {
|
||||||
foreach($paramTags as $tag){
|
/** @var ParamTag $tag */
|
||||||
// Convert the keywords
|
foreach ($paramTags as $tag) {
|
||||||
$content = $this->convertKeywords($tag->getContent());
|
// Convert the keywords
|
||||||
$tag->setContent($content);
|
$content = $this->convertKeywords($tag->getContent());
|
||||||
|
$tag->setContent($content);
|
||||||
// Get the expanded type and re-set the content
|
|
||||||
$content = $tag->getType() . ' ' . $tag->getVariableName() . ' ' . $tag->getDescription();
|
// Get the expanded type and re-set the content
|
||||||
$tag->setContent(trim($content));
|
$content = $tag->getType() . ' ' . $tag->getVariableName() . ' ' . $tag->getDescription();
|
||||||
}
|
$tag->setContent(trim($content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Normalize the return tag (make full namespace, replace interfaces)
|
/**
|
||||||
*
|
* Normalize the return tag (make full namespace, replace interfaces)
|
||||||
* @param DocBlock $phpdoc
|
*
|
||||||
*/
|
* @param DocBlock $phpdoc
|
||||||
protected function normalizeReturn(DocBlock $phpdoc)
|
*/
|
||||||
{
|
protected function normalizeReturn(DocBlock $phpdoc)
|
||||||
//Get the return type and adjust them for beter autocomplete
|
{
|
||||||
$returnTags = $phpdoc->getTagsByName('return');
|
//Get the return type and adjust them for beter autocomplete
|
||||||
if ($returnTags) {
|
$returnTags = $phpdoc->getTagsByName('return');
|
||||||
/** @var ReturnTag $tag */
|
if ($returnTags) {
|
||||||
$tag = reset($returnTags);
|
/** @var ReturnTag $tag */
|
||||||
// Get the expanded type
|
$tag = reset($returnTags);
|
||||||
$returnValue = $tag->getType();
|
// Get the expanded type
|
||||||
|
$returnValue = $tag->getType();
|
||||||
// Replace the interfaces
|
|
||||||
foreach($this->interfaces as $interface => $real){
|
// Replace the interfaces
|
||||||
$returnValue = str_replace($interface, $real, $returnValue);
|
foreach ($this->interfaces as $interface => $real) {
|
||||||
}
|
$returnValue = str_replace($interface, $real, $returnValue);
|
||||||
|
}
|
||||||
// Set the changed content
|
|
||||||
$tag->setContent($returnValue . ' ' . $tag->getDescription());
|
// Set the changed content
|
||||||
$this->return = $returnValue;
|
$tag->setContent($returnValue . ' ' . $tag->getDescription());
|
||||||
}else{
|
$this->return = $returnValue;
|
||||||
$this->return = null;
|
} else {
|
||||||
}
|
$this->return = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Convert keywwords that are incorrect.
|
/**
|
||||||
*
|
* Convert keywwords that are incorrect.
|
||||||
* @param string $string
|
*
|
||||||
* @return string
|
* @param string $string
|
||||||
*/
|
* @return string
|
||||||
protected function convertKeywords($string)
|
*/
|
||||||
{
|
protected function convertKeywords($string)
|
||||||
$string = str_replace('\Closure', 'Closure', $string);
|
{
|
||||||
$string = str_replace('Closure', '\Closure', $string);
|
$string = str_replace('\Closure', 'Closure', $string);
|
||||||
$string = str_replace('dynamic', 'mixed', $string);
|
$string = str_replace('Closure', '\Closure', $string);
|
||||||
|
$string = str_replace('dynamic', 'mixed', $string);
|
||||||
return $string;
|
|
||||||
}
|
return $string;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Should the function return a value?
|
/**
|
||||||
*
|
* Should the function return a value?
|
||||||
* @return bool
|
*
|
||||||
*/
|
* @return bool
|
||||||
public function shouldReturn()
|
*/
|
||||||
{
|
public function shouldReturn()
|
||||||
if($this->return !== "void" && $this->method->name !== "__construct"){
|
{
|
||||||
return true;
|
if ($this->return !== "void" && $this->method->name !== "__construct") {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
return false;
|
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Get the parameters and format them correctly
|
/**
|
||||||
*
|
* Get the parameters and format them correctly
|
||||||
* @param $method
|
*
|
||||||
* @return array
|
* @param \ReflectionMethod $method
|
||||||
*/
|
* @return array
|
||||||
public function getParameters($method)
|
*/
|
||||||
{
|
public function getParameters($method)
|
||||||
//Loop through the default values for paremeters, and make the correct output string
|
{
|
||||||
$params = array();
|
//Loop through the default values for paremeters, and make the correct output string
|
||||||
$paramsWithDefault = array();
|
$params = array();
|
||||||
foreach ($method->getParameters() as $param) {
|
$paramsWithDefault = array();
|
||||||
$paramStr = '$' . $param->getName();
|
foreach ($method->getParameters() as $param) {
|
||||||
$params[] = $paramStr;
|
$paramStr = '$' . $param->getName();
|
||||||
if ($param->isOptional()) {
|
$params[] = $paramStr;
|
||||||
$default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
|
if ($param->isOptional()) {
|
||||||
if (is_bool($default)) {
|
$default = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
|
||||||
$default = $default ? 'true' : 'false';
|
if (is_bool($default)) {
|
||||||
} elseif (is_array($default)) {
|
$default = $default ? 'true' : 'false';
|
||||||
$default = 'array()';
|
} elseif (is_array($default)) {
|
||||||
} elseif (is_null($default)) {
|
$default = 'array()';
|
||||||
$default = 'null';
|
} elseif (is_null($default)) {
|
||||||
} elseif (is_int($default)) {
|
$default = 'null';
|
||||||
//$default = $default;
|
} elseif (is_int($default)) {
|
||||||
} elseif (is_resource($default)) {
|
//$default = $default;
|
||||||
//skip to not fail
|
} elseif (is_resource($default)) {
|
||||||
} else {
|
//skip to not fail
|
||||||
$default = "'" . trim($default) . "'";
|
} else {
|
||||||
}
|
$default = "'" . trim($default) . "'";
|
||||||
$paramStr .= " = $default";
|
}
|
||||||
}
|
$paramStr .= " = $default";
|
||||||
$paramsWithDefault[] = $paramStr;
|
}
|
||||||
}
|
$paramsWithDefault[] = $paramStr;
|
||||||
|
}
|
||||||
$this->params = $params;
|
|
||||||
$this->params_with_default = $paramsWithDefault;
|
$this->params = $params;
|
||||||
}
|
$this->params_with_default = $paramsWithDefault;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* @param \ReflectionMethod $reflectionMethod
|
/**
|
||||||
* @return DocBlock
|
* @param \ReflectionMethod $reflectionMethod
|
||||||
*/
|
* @return DocBlock
|
||||||
protected function getInheritDoc($reflectionMethod)
|
*/
|
||||||
{
|
protected function getInheritDoc($reflectionMethod)
|
||||||
$parentClass = $reflectionMethod->getDeclaringClass()->getParentClass();
|
{
|
||||||
|
$parentClass = $reflectionMethod->getDeclaringClass()->getParentClass();
|
||||||
//Get either a parent or the interface
|
|
||||||
if ($parentClass) {
|
//Get either a parent or the interface
|
||||||
$method = $parentClass->getMethod($reflectionMethod->getName());
|
if ($parentClass) {
|
||||||
} else {
|
$method = $parentClass->getMethod($reflectionMethod->getName());
|
||||||
$method = $reflectionMethod->getPrototype();
|
} else {
|
||||||
}
|
$method = $reflectionMethod->getPrototype();
|
||||||
if ($method) {
|
}
|
||||||
$namespace = $method->getDeclaringClass()->getNamespaceName();
|
if ($method) {
|
||||||
$phpdoc = new DocBlock($method, new Context($namespace));
|
$namespace = $method->getDeclaringClass()->getNamespaceName();
|
||||||
|
$phpdoc = new DocBlock($method, new Context($namespace));
|
||||||
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
|
|
||||||
//Not at the end yet, try another parent/interface..
|
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
|
||||||
return $this->getInheritDoc($method);
|
//Not at the end yet, try another parent/interface..
|
||||||
} else {
|
return $this->getInheritDoc($method);
|
||||||
return $phpdoc;
|
} else {
|
||||||
}
|
return $phpdoc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
|
class ExampleTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that we can actually instantiate the class
|
||||||
|
*/
|
||||||
|
public function testCanInstantiate()
|
||||||
|
{
|
||||||
|
$reflectionClass = new \ReflectionClass(ExampleClass::class);
|
||||||
|
$reflectionMethod = $reflectionClass->getMethod('setName');
|
||||||
|
|
||||||
|
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Method::class, $method);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the output of a class
|
||||||
|
*/
|
||||||
|
public function testOutput()
|
||||||
|
{
|
||||||
|
$reflectionClass = new \ReflectionClass(ExampleClass::class);
|
||||||
|
$reflectionMethod = $reflectionClass->getMethod('setName');
|
||||||
|
|
||||||
|
$method = new Method($reflectionMethod, 'Example', $reflectionClass);
|
||||||
|
|
||||||
|
$output = '/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param string $last
|
||||||
|
* @param string $first
|
||||||
|
* @static
|
||||||
|
*/';
|
||||||
|
$this->assertEquals($output, $method->getDocComment(''));
|
||||||
|
$this->assertEquals('setName', $method->getName());
|
||||||
|
$this->assertEquals('\\'.ExampleClass::class, $method->getDeclaringClass());
|
||||||
|
$this->assertEquals('$last, $first', $method->getParams(true));
|
||||||
|
$this->assertEquals(['$last', '$first'], $method->getParams(false));
|
||||||
|
$this->assertEquals('$last, $first = \'Barry\'', $method->getParamsWithDefault(true));
|
||||||
|
$this->assertEquals(['$last', '$first = \'Barry\''], $method->getParamsWithDefault(false));
|
||||||
|
$this->assertEquals(true, $method->shouldReturn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExampleClass
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $last
|
||||||
|
* @param string $first
|
||||||
|
*/
|
||||||
|
public function setName($last, $first = 'Barry')
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user