PHP code example of diego-rlima / artisan-make-file-location

1. Go to this page and download the library: Download diego-rlima/artisan-make-file-location library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

diego-rlima / artisan-make-file-location example snippets


DRL\AMFL\ArtisanServiceProvider::class,

return [
    /*
    |--------------------------------------------------------------------------
    | Files namespaces
    |--------------------------------------------------------------------------
    */
    // List of all files with namespace. Eg.:
    'controller' => '{root}\{prefix|default:Http}\Controllers\{suffix}',
    'test' => '{root}\{prefix}\{type}\{suffix}',

    /*
    |--------------------------------------------------------------------------
    | Files locations
    |--------------------------------------------------------------------------
    */
    // List of all files without namespace. Eg.:
    'seeder' => '{root}/{prefix}/seeds/{name}.php',
];

return [
    // Now you will always have to enter a prefix when creating a Model.
    'model' => '{root}\{prefix|red}',
];

return [
    // Now, if you do not set a prefix, the default value will be used.
    'model' => '{root}\{prefix|default:Models}',

    // The same for the suffix.
    'rule' => '{root}\{prefix}\Rules\{suffix|default:Admin}',
];

namespace App\Console\Commands;

use Illuminate\Console\GeneratorCommand;

class FooBarMakeCommand extends GeneratorCommand
{
    protected $name = 'make:foobar';

    protected $description = 'Create a new bar';

    protected $type = 'FooBar';

    protected function getStub()
    {
        return __DIR__ . '/stubs/bar.stub';
    }

    protected function getDefaultNamespace($rootNamespace)
    {
        return $rootNamespace.'\Foo\Bar';
    }
}

use DRL\AMFL\TraitCommand;

class FooBarMakeCommand extends GeneratorCommand
{
    // You will use trait.
    use TraitCommand;

    // You will use the amflCustomNamespace() method to retrieve the correct namespace and return it in the getDefaultNamespace() method.
    protected function getDefaultNamespace($rootNamespace)
    {
        return $this->amflCustomNamespace($rootNamespace);
    }

    // You will create the amflInit() method and load the correct settings.
    protected function amflInit()
    {
        $this->amflCommandSetup('foobar'); // "foobar" must be the configuration key within your "config/amfl.php" file;
    }

    // Code omitted
}

use DRL\AMFL\TraitCommand;

class FooBarMakeCommand extends GeneratorCommand
{
    use TraitCommand;

    // You will use the amflCustomPath() method to retrieve the correct path and return it in the getPath() method.
    protected function getPath($name)
    {
        $rootPath = $this->laravel->basePath();

        return return $this->amflCustomPath($rootPath, $name);
    }

    protected function amflInit()
    {
        $this->amflCommandSetup('foobar');
    }
}

use DRL\AMFL\CommandsList;
use App\Console\Commands\FooBarMakeCommand;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        // The first argument must be the name of the command. The second is a function that receives the $app variable and returns an instance of the command class.
        CommandsList::extend('command.foobar.make', function ($app) {
            return new FooBarMakeCommand($app['files']);
        });
    }
}

return [
    // For files with namespace.
    'foobar' => '{root}\{prefix}\Foo\{suffix}',

    // For files without namespace.
    'foobar' => '{root}/{prefix}/Foo/{name}.php',
];
bash
$ php artisan make:controller ProductController --prefix=Units\\Products\\Controllers
bash
$ php artisan make:controller ProductController --suffix=Products
bash
$ php artisan vendor:publish --provider="DRL\AMFL\ArtisanServiceProvider"