foothing/laravel-wrappr

View on GitHub
src/Foothing/Wrappr/Commands/Install.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php namespace Foothing\Wrappr\Commands;

use Foothing\Wrappr\Installer\RouteInstaller;
use Illuminate\Console\Command;

class Install extends Command {

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'wrappr:install';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Bind routes to permissions.';

    /**
     * @var \Foothing\Wrappr\Installer\RouteInstaller
     */
    protected $routes;

    public function __construct(RouteInstaller $routes) {
        parent::__construct();
        $this->routes = $routes;
    }

    public function handle() {
        \DB::table('routes')->truncate();
        try {
            foreach(config('wrappr.install.routes') as $route) {
                $this->routes->route($route['verb'], $route['path'])->requires($route['permissions']);
                if (isset($route['resource'])) {
                    $this->routes->on($route['resource']);
                }
            }

            $this->routes->install();

        } catch (\Exception $ex) {
            print ($ex->getTraceAsString());
        }
    }
}