Skip to content

Instantly share code, notes, and snippets.

@Caffe1neAdd1ct
Last active March 15, 2018 13:51
Show Gist options
  • Save Caffe1neAdd1ct/da1589e3af6bb0341caef666692ca9a9 to your computer and use it in GitHub Desktop.
Save Caffe1neAdd1ct/da1589e3af6bb0341caef666692ca9a9 to your computer and use it in GitHub Desktop.
Artisan IDE Helper Generate On Laravel 4.2 Local Env Only + NetBeans ide_helper_models rewrite
<?php
use Illuminate\Console\Command;
/**
* Run IDE generation through artisan when on the local environment.
* This should only be called by composer install/update.
*
* @author Kevin Andrews <[email protected]>
*/
class ComposerDevelopment extends Command
{
protected $name = 'composer:development';
protected $description = 'Run post-composer install commands';
public function fire()
{
if($this->laravel->environment('local')) {
$this->call('ide-helper:models', ['--nowrite' => true]);
$this->call('ide-helper:meta');
$this->call('ide-helper:generate');
$this->call('composer:netbeans');
}
}
}
<?php
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
/**
* Modify Generated IDE Helper Files for compatibility with NetBeans
*
* @author Kevin Andrews <[email protected]>
*/
class ComposerIdeHelperNetbeans extends Command
{
protected $name = 'composer:netbeans';
protected $description = 'Run post-composer netbeans ide helper compatability commands';
/**
* Removes class references on @method static hints
*/
public function fire()
{
if(!$this->laravel->environment('local')) {
$this->info($this->name . ' App not running locally, refusing to run netbeans autocomplete helper.');
return true;
}
$ideHelperModelFilePath = base_path('_ide_helper_models.php');
if(!File::exists($ideHelperModelFilePath)) {
$this->error($this->name . ' Helper Models file unavailable: ' . $ideHelperModelFilePath);
return false;
}
$content = File::get($ideHelperModelFilePath);
if(!$content) {
$this->error('Failed to retrieve file content ' . $ideHelperModelFilePath);
return false;
}
$newContent = preg_replace("/\@method static \\\\(.*)\s([a-zA-Z0-9]+)\((.*)\)/", "$2($3)", $content);
$writeResult = File::put($ideHelperModelFilePath, $newContent);
if(!$writeResult) {
$this->error('Failed to write new content to ' . $ideHelperModelFilePath);
return false;
}
return;
}
}
@Caffe1neAdd1ct
Copy link
Author

Caffe1neAdd1ct commented Dec 4, 2017

composer.json:

"scripts": {
        "post-install-cmd": [
            "@php artisan clear-compiled",
            "@php artisan composer:development",
            "@php artisan optimize"
        ],
        "post-update-cmd": [
            "@php artisan clear-compiled",
            "@php artisan composer:development",
            "@php artisan optimize"
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate",
            "@php artisan clear-compiled",
            "@php artisan composer:development",
            "@php artisan optimize"
        ]
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment