mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-23 04:23:09 +00:00
Add dynamic whereField()
Fixes #61 Also added backslash to method return types and use full Str facade, not an alias.
This commit is contained in:
@@ -3,13 +3,15 @@
|
||||
* Laravel IDE Helper Generator
|
||||
*
|
||||
* @author Barry vd. Heuvel <[email protected]>
|
||||
* @copyright 2013 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
|
||||
* @link https://github.com/barryvdh/laravel-ide-helper
|
||||
*/
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\ClassLoader\ClassMapGenerator;
|
||||
@@ -17,6 +19,7 @@ use phpDocumentor\Reflection\DocBlock;
|
||||
use phpDocumentor\Reflection\DocBlock\Context;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||
|
||||
/**
|
||||
* A command to generate autocomplete information for your IDE
|
||||
*
|
||||
@@ -231,6 +234,7 @@ class ModelsCommand extends Command {
|
||||
break;
|
||||
}
|
||||
$this->setProperty($name, $type, true, true);
|
||||
$this->setMethod(Str::camel("where_".$name), '\\'.get_class($model), array('$value'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,29 +246,29 @@ class ModelsCommand extends Command {
|
||||
$methods = get_class_methods($model);
|
||||
if($methods){
|
||||
foreach($methods as $method){
|
||||
if(\Str::startsWith($method, 'get') && \Str::endsWith($method, 'Attribute') && $method !== 'getAttribute'){
|
||||
if(Str::startsWith($method, 'get') && Str::endsWith($method, 'Attribute') && $method !== 'getAttribute'){
|
||||
//Magic get<name>Attribute
|
||||
$name = \Str::snake(substr($method, 3, -9));
|
||||
$name = Str::snake(substr($method, 3, -9));
|
||||
if(!empty($name)){
|
||||
$this->setProperty($name, null, true, null);
|
||||
}
|
||||
}elseif(\Str::startsWith($method, 'set') && \Str::endsWith($method, 'Attribute') && $method !== 'setAttribute'){
|
||||
}elseif(Str::startsWith($method, 'set') && Str::endsWith($method, 'Attribute') && $method !== 'setAttribute'){
|
||||
//Magic set<name>Attribute
|
||||
$name = \Str::snake(substr($method, 3, -9));
|
||||
$name = Str::snake(substr($method, 3, -9));
|
||||
if(!empty($name)){
|
||||
$this->setProperty($name, null, null, true);
|
||||
}
|
||||
}elseif(\Str::startsWith($method, 'scope') && $method !== 'scopeQuery'){
|
||||
}elseif(Str::startsWith($method, 'scope') && $method !== 'scopeQuery'){
|
||||
//Magic set<name>Attribute
|
||||
$name = \Str::camel(substr($method, 5));
|
||||
$name = Str::camel(substr($method, 5));
|
||||
if(!empty($name)){
|
||||
$reflection = new \ReflectionMethod($model, $method);
|
||||
$args = $this->getParameters($reflection);
|
||||
//Remove the first ($query) argument
|
||||
array_shift($args);
|
||||
$this->setMethod($name, $reflection->class, $args);
|
||||
$this->setMethod($name, '\\'.$reflection->class, $args);
|
||||
}
|
||||
}elseif(!method_exists('Eloquent', $method) && !\Str::startsWith($method, 'get')){
|
||||
}elseif(!method_exists('Eloquent', $method) && !Str::startsWith($method, 'get')){
|
||||
|
||||
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
||||
$reflection = new \ReflectionMethod($model, $method);
|
||||
|
||||
Reference in New Issue
Block a user