mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
981ff45b43 | ||
|
|
8174730714 | ||
|
|
ae5b623cf2 | ||
|
|
eff51d41b3 | ||
|
|
b14d983f74 | ||
|
|
1fdc866fb0 | ||
|
|
d7359b86d4 | ||
|
|
5d8d93273f | ||
|
|
30e5300e49 | ||
|
|
593e0d4aa7 | ||
|
|
e7d4cb322f | ||
|
|
5318f485e2 | ||
|
|
7db1843473 | ||
|
|
1989d0e794 | ||
|
|
09db8c9a76 | ||
|
|
4aa43fa613 | ||
|
|
d55b48476e | ||
|
|
45e84b9070 | ||
|
|
f472c26601 | ||
|
|
1deadced46 | ||
|
|
e1d1352ac5 | ||
|
|
65e3278c86 | ||
|
|
efd7e51566 | ||
|
|
2a5dda6a27 | ||
|
|
6577af8464 | ||
|
|
6c7bc371f9 | ||
|
|
217b8989c2 | ||
|
|
c003eb40d7 | ||
|
|
1a3d32f0d1 | ||
|
|
bd733b7b7c | ||
|
|
93630fdf62 | ||
|
|
f64ed52205 | ||
|
|
ba28841870 | ||
|
|
b02a0bc6c9 | ||
|
|
a665961fb9 | ||
|
|
83852e9de0 | ||
|
|
d2f29d997b | ||
|
|
cbacb28f19 | ||
|
|
930e5bd301 | ||
|
|
930d258cd4 | ||
|
|
94248adae8 | ||
|
|
50ecd8b815 | ||
|
|
1b70277203 | ||
|
|
87a03fd9c4 | ||
|
|
b8a73bcab9 | ||
|
|
0556991c69 | ||
|
|
be78ac62cd | ||
|
|
265f00c322 | ||
|
|
bbd96d3616 | ||
|
|
8d913089db | ||
|
|
9a2588cb3a | ||
|
|
e7fa36bdc3 | ||
|
|
b1e868c5fc | ||
|
|
203d60dc8c | ||
|
|
f5275b700a | ||
|
|
046a9bcc77 | ||
|
|
c6191830ab | ||
|
|
cfff7721bc | ||
|
|
4691bc5fbd | ||
|
|
b1b05b694b | ||
|
|
98d6087a1e | ||
|
|
c7b7ebf1b5 | ||
|
|
17982029f0 | ||
|
|
bda5120e9a | ||
|
|
d961482d22 | ||
|
|
8852b1ca9d | ||
|
|
b644e48801 | ||
|
|
09610da602 | ||
|
|
2d56afce8e | ||
|
|
8ab907f219 | ||
|
|
e29e035135 | ||
|
|
7b2786ac2b | ||
|
|
76bd86dbaf | ||
|
|
7b067198a6 | ||
|
|
b6f525b320 | ||
|
|
d65f1cedcd | ||
|
|
df6b1b6f82 | ||
|
|
76a1952c41 | ||
|
|
d45b02efb1 | ||
|
|
b0abafb8c7 | ||
|
|
6b0e9ec48d | ||
|
|
721a7cd3f7 |
+3
-7
@@ -1,10 +1,9 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
|
||||
# This triggers builds to run on the new TravisCI infrastructure.
|
||||
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||
@@ -17,7 +16,7 @@ cache:
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.5
|
||||
- php: 7.0
|
||||
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
|
||||
|
||||
before_script:
|
||||
@@ -25,7 +24,4 @@ before_script:
|
||||
|
||||
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
|
||||
- vendor/bin/phpunit
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Barry vd. Heuvel <barryvdh@gmail.com>
|
||||
Copyright (c) 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
|
||||
|
||||
+13
-11
@@ -10,19 +10,20 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"illuminate/support": "^5.0,<5.7",
|
||||
"illuminate/console": "^5.0,<5.7",
|
||||
"illuminate/filesystem": "^5.0,<5.7",
|
||||
"php": ">=7",
|
||||
"illuminate/support": "^5.5,<5.8",
|
||||
"illuminate/console": "^5.5,<5.8",
|
||||
"illuminate/filesystem": "^5.5,<5.8",
|
||||
"barryvdh/reflection-docblock": "^2.0.4",
|
||||
"symfony/class-loader": "^2.3|^3.0"
|
||||
"composer/composer": "^1.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/config": "^5.0,<5.7",
|
||||
"illuminate/view": "^5.0,<5.7",
|
||||
"illuminate/config": "^5.1,<5.8",
|
||||
"illuminate/view": "^5.1,<5.8",
|
||||
"phpro/grumphp": "^0.14",
|
||||
"phpunit/phpunit" : "4.*",
|
||||
"scrutinizer/ocular": "~1.1",
|
||||
"squizlabs/php_codesniffer": "~2.3",
|
||||
"squizlabs/php_codesniffer": "^3",
|
||||
"doctrine/dbal": "~2.3"
|
||||
},
|
||||
"suggest": {
|
||||
@@ -35,16 +36,17 @@
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
":vendor\\:package_name\\": "tests"
|
||||
"Barryvdh\\LaravelIdeHelper\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit",
|
||||
"cs": "phpcs --standard=psr2 src/"
|
||||
"check-style": "phpcs -p --standard=PSR2 src/",
|
||||
"fix-style": "phpcbf -p --standard=PSR2 src/"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.3-dev"
|
||||
"dev-master": "2.5-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
|
||||
@@ -153,13 +153,13 @@ return array(
|
||||
|
|
||||
| For example, normally you would see this:
|
||||
|
|
||||
| * @property \Carbon\Carbon $created_at
|
||||
| * @property \Carbon\Carbon $updated_at
|
||||
| * @property \Illuminate\Support\Carbon $created_at
|
||||
| * @property \Illuminate\Support\Carbon $updated_at
|
||||
|
|
||||
| With this enabled, the properties will be this:
|
||||
|
|
||||
| * @property \Carbon\Carbon $createdAt
|
||||
| * @property \Carbon\Carbon $updatedAt
|
||||
| * @property \Illuminate\Support\Carbon $createdAt
|
||||
| * @property \Illuminate\Support\Carbon $updatedAt
|
||||
|
|
||||
| Note, it is currently an all-or-nothing option.
|
||||
|
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
parameters:
|
||||
git_dir: .
|
||||
bin_dir: vendor/bin
|
||||
tasks:
|
||||
phpunit:
|
||||
config_file: ~
|
||||
testsuite: ~
|
||||
group: []
|
||||
always_execute: false
|
||||
phpcs:
|
||||
standard: PSR2
|
||||
warning_severity: ~
|
||||
ignore_patterns:
|
||||
- tests/
|
||||
triggered_by: [php]
|
||||
+1
-8
@@ -10,7 +10,7 @@
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name=":vendor Test Suite">
|
||||
<testsuite name="Unit Tests">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
@@ -19,11 +19,4 @@
|
||||
<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>
|
||||
@@ -37,6 +37,7 @@ After updating composer, add the service provider to the `providers` array in `c
|
||||
```php
|
||||
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
|
||||
```
|
||||
**Laravel 5.5** uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
|
||||
|
||||
To install this package on only development systems, add the `--dev` flag to your composer command:
|
||||
|
||||
@@ -66,7 +67,7 @@ You can now re-generate the docs yourself (for future updates)
|
||||
php artisan ide-helper:generate
|
||||
```
|
||||
|
||||
Note: `bootstrap/compiled.php` has to be cleared first, so run `php artisan clear-compiled` before generating (and `php artisan optimize` after).
|
||||
Note: `bootstrap/compiled.php` has to be cleared first, so run `php artisan clear-compiled` before generating.
|
||||
|
||||
You can configure your composer.json to do this after each commit:
|
||||
|
||||
@@ -75,8 +76,7 @@ You can configure your composer.json to do this after each commit:
|
||||
"post-update-cmd": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
|
||||
"php artisan ide-helper:generate",
|
||||
"php artisan ide-helper:meta",
|
||||
"php artisan optimize"
|
||||
"php artisan ide-helper:meta"
|
||||
]
|
||||
},
|
||||
```
|
||||
@@ -122,8 +122,8 @@ php artisan ide-helper:models Post
|
||||
* @property integer $author_id
|
||||
* @property string $title
|
||||
* @property string $text
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
* @property-read \User $author
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Comment[] $comments
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<?= '<?php' ?>
|
||||
<?php
|
||||
/**
|
||||
* @var \Barryvdh\LaravelIdeHelper\Alias[][] $namespaces_by_alias_ns
|
||||
* @var \Barryvdh\LaravelIdeHelper\Alias[][] $namespaces_by_extends_ns
|
||||
* @var bool $include_fluent
|
||||
* @var string $helpers
|
||||
*/
|
||||
?>
|
||||
|
||||
// @formatter:off
|
||||
|
||||
/**
|
||||
* A helper file for Laravel 5, to provide autocomplete information to your IDE
|
||||
@@ -15,6 +25,7 @@
|
||||
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||
<?php foreach($aliases as $alias): ?>
|
||||
|
||||
<?= trim($alias->getDocComment(' ')) ?>
|
||||
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
|
||||
<?php foreach($alias->getMethods() as $method): ?>
|
||||
|
||||
@@ -25,7 +36,7 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
|
||||
}
|
||||
<?php endforeach; ?>
|
||||
}
|
||||
@@ -47,7 +58,7 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getName() ?>(<?= $method->getParams() ?>);
|
||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
|
||||
}
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>}
|
||||
@@ -71,7 +82,7 @@ namespace Illuminate\Support {
|
||||
* @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 default($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
|
||||
@@ -79,10 +90,11 @@ namespace Illuminate\Support {
|
||||
* @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 nullable(bool $value = true) 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
|
||||
* @method Fluent change() Add the change modifier
|
||||
*/
|
||||
class Fluent {}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?= '<?php' ?>
|
||||
|
||||
// @formatter:off
|
||||
|
||||
namespace PHPSTORM_META {
|
||||
|
||||
/**
|
||||
|
||||
+72
-4
@@ -10,6 +10,11 @@
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
use Barryvdh\Reflection\DocBlock;
|
||||
use Barryvdh\Reflection\DocBlock\Context;
|
||||
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||
use ReflectionClass;
|
||||
|
||||
class Alias
|
||||
{
|
||||
protected $alias;
|
||||
@@ -27,6 +32,7 @@ class Alias
|
||||
protected $valid = false;
|
||||
protected $magicMethods = array();
|
||||
protected $interfaces = array();
|
||||
protected $phpdoc = null;
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
@@ -53,10 +59,17 @@ class Alias
|
||||
}
|
||||
|
||||
$this->addClass($this->root);
|
||||
$this->detectFake();
|
||||
$this->detectNamespace();
|
||||
$this->detectClassType();
|
||||
$this->detectExtendsNamespace();
|
||||
|
||||
if (!empty($this->namespace)) {
|
||||
//Create a DocBlock and serializer instance
|
||||
$this->phpdoc = new DocBlock(new ReflectionClass($alias), new Context($this->namespace));
|
||||
}
|
||||
|
||||
|
||||
if ($facade === '\Illuminate\Database\Eloquent\Model') {
|
||||
$this->usedMethods = array('decrement', 'increment');
|
||||
}
|
||||
@@ -158,7 +171,7 @@ class Alias
|
||||
/**
|
||||
* Get the methods found by this Alias
|
||||
*
|
||||
* @return array
|
||||
* @return array|Method[]
|
||||
*/
|
||||
public function getMethods()
|
||||
{
|
||||
@@ -167,6 +180,30 @@ class Alias
|
||||
return $this->methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect class returned by ::fake()
|
||||
*/
|
||||
protected function detectFake()
|
||||
{
|
||||
$facade = $this->facade;
|
||||
|
||||
if (!method_exists($facade, 'fake')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$real = $facade::getFacadeRoot();
|
||||
|
||||
try {
|
||||
$facade::fake();
|
||||
$fake = $facade::getFacadeRoot();
|
||||
if ($fake !== $real) {
|
||||
$this->addClass(get_class($fake));
|
||||
}
|
||||
} finally {
|
||||
$facade::swap($real);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the namespace
|
||||
*/
|
||||
@@ -273,7 +310,7 @@ class Alias
|
||||
$method = new \ReflectionMethod($className, $name);
|
||||
$class = new \ReflectionClass($className);
|
||||
|
||||
if (!in_array($method->name, $this->usedMethods)) {
|
||||
if (!in_array($magic, $this->usedMethods)) {
|
||||
if ($class !== $this->root) {
|
||||
$this->methods[] = new Method($method, $this->alias, $class, $magic, $this->interfaces);
|
||||
}
|
||||
@@ -319,10 +356,9 @@ class Alias
|
||||
$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->getMacroFunction($macro_func),
|
||||
$this->alias,
|
||||
$reflection,
|
||||
$macro_name,
|
||||
@@ -333,6 +369,38 @@ class Alias
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $macro_func
|
||||
*
|
||||
* @return \ReflectionFunctionAbstract
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function getMacroFunction($macro_func)
|
||||
{
|
||||
if (is_array($macro_func) && is_callable($macro_func)) {
|
||||
return new \ReflectionMethod($macro_func[0], $macro_func[1]);
|
||||
}
|
||||
|
||||
return new \ReflectionFunction($macro_func);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the docblock for this alias
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDocComment($prefix = "\t\t")
|
||||
{
|
||||
$serializer = new DocBlockSerializer(1, $prefix);
|
||||
|
||||
if ($this->phpdoc) {
|
||||
return $serializer->getDocComment($this->phpdoc);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an error.
|
||||
*
|
||||
|
||||
@@ -115,7 +115,6 @@ class GeneratorCommand extends Command
|
||||
|
||||
if ($written !== false) {
|
||||
$this->info("A new helper file was written to $filename");
|
||||
Eloquent::writeEloquentModelHelper($this, $this->files);
|
||||
} else {
|
||||
$this->error("The helper file could not be created at $filename");
|
||||
}
|
||||
|
||||
@@ -122,7 +122,11 @@ class MetaCommand extends Command
|
||||
$abstracts = $this->laravel->getBindings();
|
||||
|
||||
// Return the abstract names only
|
||||
return array_keys($abstracts);
|
||||
$keys = array_keys($abstracts);
|
||||
|
||||
sort($keys);
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,14 +10,15 @@
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Console;
|
||||
|
||||
use Composer\Autoload\ClassMapGenerator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use ReflectionClass;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||
use Barryvdh\Reflection\DocBlock;
|
||||
use Barryvdh\Reflection\DocBlock\Context;
|
||||
use Barryvdh\Reflection\DocBlock\Tag;
|
||||
@@ -56,6 +57,7 @@ class ModelsCommand extends Command
|
||||
protected $write = false;
|
||||
protected $dirs = array();
|
||||
protected $reset;
|
||||
protected $keep_text;
|
||||
/**
|
||||
* @var bool[string]
|
||||
*/
|
||||
@@ -86,12 +88,15 @@ class ModelsCommand extends Command
|
||||
$model = $this->argument('model');
|
||||
$ignore = $this->option('ignore');
|
||||
$this->reset = $this->option('reset');
|
||||
if ($this->option('smart-reset')) {
|
||||
$this->keep_text = $this->reset = true;
|
||||
}
|
||||
$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 (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
||||
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?"
|
||||
)
|
||||
) {
|
||||
$this->write = true;
|
||||
@@ -136,6 +141,7 @@ class ModelsCommand extends Command
|
||||
array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
|
||||
array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
|
||||
array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
|
||||
array('smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'),
|
||||
array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
|
||||
);
|
||||
}
|
||||
@@ -145,6 +151,8 @@ class ModelsCommand extends Command
|
||||
|
||||
|
||||
$output = "<?php
|
||||
|
||||
// @formatter:off
|
||||
/**
|
||||
* A helper file for your Eloquent Models
|
||||
* Copy the phpDocs from this file to the correct Model,
|
||||
@@ -179,10 +187,9 @@ class ModelsCommand extends Command
|
||||
if (class_exists($name)) {
|
||||
try {
|
||||
// handle abstract classes, interfaces, ...
|
||||
$reflectionClass = new \ReflectionClass($name);
|
||||
$reflectionClass = new ReflectionClass($name);
|
||||
|
||||
if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')
|
||||
|| $reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Relations\Pivot')) {
|
||||
if (!$reflectionClass->isSubclassOf('Illuminate\Database\Eloquent\Model')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -277,7 +284,7 @@ class ModelsCommand extends Command
|
||||
break;
|
||||
case 'date':
|
||||
case 'datetime':
|
||||
$realType = '\Carbon\Carbon';
|
||||
$realType = '\Illuminate\Support\Carbon';
|
||||
break;
|
||||
case 'collection':
|
||||
$realType = '\Illuminate\Support\Collection';
|
||||
@@ -291,6 +298,10 @@ class ModelsCommand extends Command
|
||||
continue;
|
||||
} else {
|
||||
$this->properties[$name]['type'] = $this->getTypeOverride($realType);
|
||||
|
||||
if (isset($this->nullableColumns[$name])) {
|
||||
$this->properties[$name]['type'] .= '|null';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,7 +348,7 @@ class ModelsCommand extends Command
|
||||
foreach ($columns as $column) {
|
||||
$name = $column->getName();
|
||||
if (in_array($name, $model->getDates())) {
|
||||
$type = '\Carbon\Carbon';
|
||||
$type = '\Illuminate\Support\Carbon';
|
||||
} else {
|
||||
$type = $column->getType()->getName();
|
||||
switch ($type) {
|
||||
@@ -433,6 +444,9 @@ class ModelsCommand extends Command
|
||||
array_shift($args);
|
||||
$this->setMethod($name, '\Illuminate\Database\Eloquent\Builder|\\' . $reflection->class, $args);
|
||||
}
|
||||
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
|
||||
$reflection = new \ReflectionClass($model);
|
||||
$this->setMethod($method, '\Illuminate\Database\Eloquent\Builder|\\' . $reflection->getName());
|
||||
} elseif (!method_exists('Illuminate\Database\Eloquent\Model', $method)
|
||||
&& !Str::startsWith($method, 'get')
|
||||
) {
|
||||
@@ -460,17 +474,30 @@ class ModelsCommand extends Command
|
||||
'morphOne',
|
||||
'morphTo',
|
||||
'morphMany',
|
||||
'morphToMany'
|
||||
'morphToMany',
|
||||
'morphedByMany'
|
||||
) as $relation) {
|
||||
$search = '$this->' . $relation . '(';
|
||||
if ($pos = stripos($code, $search)) {
|
||||
//Resolve the relation's model to a Relation object.
|
||||
$methodReflection = new \ReflectionMethod($model, $method);
|
||||
if ($methodReflection->getNumberOfParameters()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$relationObj = $model->$method();
|
||||
|
||||
if ($relationObj instanceof Relation) {
|
||||
$relatedModel = '\\' . get_class($relationObj->getRelated());
|
||||
|
||||
$relations = ['hasManyThrough', 'belongsToMany', 'hasMany', 'morphMany', 'morphToMany'];
|
||||
$relations = [
|
||||
'hasManyThrough',
|
||||
'belongsToMany',
|
||||
'hasMany',
|
||||
'morphMany',
|
||||
'morphToMany',
|
||||
'morphedByMany',
|
||||
];
|
||||
if (in_array($relation, $relations)) {
|
||||
//Collection or array of models (because Collection is Arrayable)
|
||||
$this->setProperty(
|
||||
@@ -575,13 +602,19 @@ class ModelsCommand extends Command
|
||||
protected function createPhpDocs($class)
|
||||
{
|
||||
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$reflection = new ReflectionClass($class);
|
||||
$namespace = $reflection->getNamespaceName();
|
||||
$classname = $reflection->getShortName();
|
||||
$originalDoc = $reflection->getDocComment();
|
||||
$keyword = $this->getClassKeyword($reflection);
|
||||
|
||||
if ($this->reset) {
|
||||
$phpdoc = new DocBlock('', new Context($namespace));
|
||||
if ($this->keep_text) {
|
||||
$phpdoc->setText(
|
||||
(new DocBlock($reflection, new Context($namespace)))->getText()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$phpdoc = new DocBlock($reflection, new Context($namespace));
|
||||
}
|
||||
@@ -661,7 +694,7 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
$output = "namespace {$namespace}{\n{$docComment}\n\tclass {$classname} extends \Eloquent {}\n}\n\n";
|
||||
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent {}\n}\n\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
@@ -764,4 +797,21 @@ class ModelsCommand extends Command
|
||||
$this->setMethod('onlyTrashed', '\Illuminate\Database\Query\Builder|\\' . get_class($model), []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $reflection
|
||||
* @return string
|
||||
*/
|
||||
private function getClassKeyword(ReflectionClass $reflection)
|
||||
{
|
||||
if ($reflection->isFinal()) {
|
||||
$keyword = 'final ';
|
||||
} elseif ($reflection->isAbstract()) {
|
||||
$keyword = 'abstract ';
|
||||
} else {
|
||||
$keyword = '';
|
||||
}
|
||||
|
||||
return $keyword;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-36
@@ -32,57 +32,27 @@ class Eloquent
|
||||
$reflection = new \ReflectionClass($class);
|
||||
$namespace = $reflection->getNamespaceName();
|
||||
$originalDoc = $reflection->getDocComment();
|
||||
|
||||
if (!$originalDoc) {
|
||||
$command->info('Unexpected no document on ' . $class);
|
||||
}
|
||||
$phpdoc = new DocBlock($reflection, new Context($namespace));
|
||||
|
||||
$mixins = $phpdoc->getTagsByName('mixin');
|
||||
$expectedMixins = [
|
||||
'\Eloquent' => false,
|
||||
'\Illuminate\Database\Eloquent\Builder' => false,
|
||||
'\Illuminate\Database\Query\Builder' => false,
|
||||
];
|
||||
|
||||
foreach ($mixins as $m) {
|
||||
$mixin = $m->getContent();
|
||||
if ($m->getContent() === '\Eloquent') {
|
||||
$command->info('Tag Exists: @mixin \Eloquent in ' . $class);
|
||||
|
||||
if (isset($expectedMixins[$mixin])) {
|
||||
$command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class);
|
||||
|
||||
$expectedMixins[$mixin] = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$changed = false;
|
||||
foreach ($expectedMixins as $expectedMixin => $present) {
|
||||
if ($present === false) {
|
||||
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $expectedMixin, $phpdoc));
|
||||
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If nothing's changed, stop here.
|
||||
if (!$changed) {
|
||||
return;
|
||||
}
|
||||
// add the Eloquent mixin
|
||||
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
|
||||
|
||||
$serializer = new DocBlockSerializer();
|
||||
$serializer->getDocComment($phpdoc);
|
||||
$docComment = $serializer->getDocComment($phpdoc);
|
||||
|
||||
/*
|
||||
The new DocBlock is appended to the beginning of the class declaration.
|
||||
Since there is no DocBlock, the declaration is used as a guide.
|
||||
*/
|
||||
if (!$originalDoc) {
|
||||
$originalDoc = 'abstract class Model implements';
|
||||
|
||||
$docComment .= "\nabstract class Model implements";
|
||||
}
|
||||
|
||||
$filename = $reflection->getFileName();
|
||||
if ($filename) {
|
||||
$contents = $files->get($filename);
|
||||
@@ -91,7 +61,7 @@ class Eloquent
|
||||
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
||||
if ($count > 0) {
|
||||
if ($files->put($filename, $contents)) {
|
||||
$command->info('Wrote expected docblock to ' . $filename);
|
||||
$command->info('Wrote @mixin \Eloquent to ' . $filename);
|
||||
} else {
|
||||
$command->error('File write failed to ' . $filename);
|
||||
}
|
||||
|
||||
+9
-4
@@ -265,15 +265,20 @@ class Generator
|
||||
'Schema' => 'Illuminate\Support\Facades\Schema',
|
||||
'Session' => 'Illuminate\Support\Facades\Session',
|
||||
'Storage' => 'Illuminate\Support\Facades\Storage',
|
||||
//'Validator' => 'Illuminate\Support\Facades\Validator',
|
||||
'Validator' => 'Illuminate\Support\Facades\Validator',
|
||||
'Gate' => 'Illuminate\Support\Facades\Gate',
|
||||
];
|
||||
|
||||
$facades = array_merge($facades, $this->config->get('app.aliases', []));
|
||||
|
||||
// Only return the ones that actually exist
|
||||
return array_filter($facades, function ($alias) {
|
||||
return class_exists($alias);
|
||||
});
|
||||
return array_filter(
|
||||
$facades,
|
||||
function ($alias) {
|
||||
return class_exists($alias);
|
||||
},
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+23
-24
@@ -10,38 +10,37 @@ class Macro extends Method
|
||||
/**
|
||||
* Macro constructor.
|
||||
*
|
||||
* @param \ReflectionFunction $method
|
||||
* @param \ReflectionFunctionAbstract $method
|
||||
* @param string $alias
|
||||
* @param \ReflectionClass $class
|
||||
* @param null $methodName
|
||||
* @param array $interfaces
|
||||
*/
|
||||
public function __construct(\ReflectionFunction $method, $alias, $class, $methodName = null, $interfaces = array())
|
||||
public function __construct(
|
||||
$method,
|
||||
$alias,
|
||||
$class,
|
||||
$methodName = null,
|
||||
$interfaces = array()
|
||||
) {
|
||||
parent::__construct($method, $alias, $class, $methodName, $interfaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionFunctionAbstract $method
|
||||
*/
|
||||
protected function initPhpDoc($method)
|
||||
{
|
||||
$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
|
||||
/**
|
||||
* @param \ReflectionFunctionAbstract $method
|
||||
* @param \ReflectionClass $class
|
||||
*/
|
||||
protected function initClassDefinedProperties($method, \ReflectionClass $class)
|
||||
{
|
||||
$this->namespace = $class->getNamespaceName();
|
||||
$this->declaringClassName = '\\' . ltrim($class->name, '\\');
|
||||
$this->root = '\\' . ltrim($class->getName(), '\\');
|
||||
}
|
||||
}
|
||||
|
||||
+37
-7
@@ -26,29 +26,32 @@ class Method
|
||||
protected $method;
|
||||
|
||||
protected $output = '';
|
||||
protected $declaringClassName;
|
||||
protected $name;
|
||||
protected $namespace;
|
||||
protected $params = array();
|
||||
protected $params_with_default = array();
|
||||
protected $interfaces = array();
|
||||
protected $real_name;
|
||||
protected $return = null;
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $method
|
||||
* @param \ReflectionMethod|\ReflectionFunctionAbstract $method
|
||||
* @param string $alias
|
||||
* @param \ReflectionClass $class
|
||||
* @param string|null $methodName
|
||||
* @param array $interfaces
|
||||
*/
|
||||
public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array())
|
||||
public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->interfaces = $interfaces;
|
||||
$this->name = $methodName ?: $method->name;
|
||||
$this->namespace = $method->getDeclaringClass()->getNamespaceName();
|
||||
$this->real_name = $method->name;
|
||||
$this->initClassDefinedProperties($method, $class);
|
||||
|
||||
//Create a DocBlock and serializer instance
|
||||
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
|
||||
$this->initPhpDoc($method);
|
||||
|
||||
//Normalize the description and inherit the docs from parents/interfaces
|
||||
try {
|
||||
@@ -64,12 +67,29 @@ class Method
|
||||
//Make the method static
|
||||
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
|
||||
|
||||
//Reference the 'real' function in the declaringclass
|
||||
$declaringClass = $method->getDeclaringClass();
|
||||
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
|
||||
//Reference the 'real' function in the declaring class
|
||||
$this->root = '\\' . ltrim($class->getName(), '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $method
|
||||
*/
|
||||
protected function initPhpDoc($method)
|
||||
{
|
||||
$this->phpdoc = new DocBlock($method, new Context($this->namespace));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $method
|
||||
* @param \ReflectionClass $class
|
||||
*/
|
||||
protected function initClassDefinedProperties($method, \ReflectionClass $class)
|
||||
{
|
||||
$declaringClass = $method->getDeclaringClass();
|
||||
$this->namespace = $declaringClass->getNamespaceName();
|
||||
$this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class wherein the function resides
|
||||
*
|
||||
@@ -112,6 +132,16 @@ class Method
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the real method name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRealName()
|
||||
{
|
||||
return $this->real_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parameters for this method
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user