Esempio n. 1
0
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     \Event::fire('press.mount', []);
     if (\App::runningInConsole()) {
         $this->consoleSetup();
     }
 }
Esempio n. 2
0
 public function saving($details)
 {
     // Level is not enough
     if ($details->user->role->level > LEVEL and !\App::runningInConsole()) {
         $this->setFlashError('alert.error.user_updated');
         return false;
     }
 }
Esempio n. 3
0
 public function __construct()
 {
     if (\App::runningInConsole()) {
         $this->request = [];
     } else {
         $this->request = ['url' => request()->url(), 'method' => request()->method(), 'input' => request()->input(), 'action' => \Route::getCurrentRoute() !== null ? \Route::getCurrentRoute()->getAction() : null, 'headers' => request()->header()];
     }
 }
 public function boot()
 {
     if (!\App::runningInConsole()) {
         $menu = file(base_path() . '/resources/content/menu.md', FILE_IGNORE_NEW_LINES);
         sort($menu);
         view()->share('menu', $menu);
     }
 }
Esempio n. 5
0
 public function _e($text, $toLog = false)
 {
     if (\App::runningInConsole()) {
         //			$this->error($text);
     }
     if ($toLog) {
         \Log::error($text);
     }
 }
Esempio n. 6
0
 public function __construct(\Exception $exception, $httpCode)
 {
     if (\App::runningInConsole()) {
         // no cli
         return;
     }
     $this->exception = $exception;
     $this->httpCode = $httpCode;
     $this->title = __('Un problème est survenu');
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     \App::make('router')->middleware('artificer-installed', InstalledMiddleware::class);
     // Avoid redirection when using CLI
     if (\App::runningInConsole() || \App::runningUnitTests()) {
         return true;
     }
     if (!self::isInstalling() && !self::isInstalled()) {
         $this->goToInstall();
     }
 }
 /**
  * Register any application services.
  *
  * @return void
  */
 public function register()
 {
     if ($this->app->environment() === 'local') {
         $this->app->register(GeneratorsServiceProvider::class);
         $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);
     }
     $this->app->singleton(ValidationInterface::class, IlluminateValidation::class);
     if ($this->app->environment() === 'local' && \App::runningInConsole()) {
         $this->app->register(ArtisanBeansServiceProvider::class);
         $this->app->register(IdeHelperServiceProvider::class);
     }
 }
Esempio n. 9
0
 public function terminate($request, $response)
 {
     if (!\App::runningInConsole() && \App::bound('veer') && app('veer')->isBooted()) {
         $timeToLoad = empty(app('veer')->statistics['loading']) ? 0 : app('veer')->statistics['loading'];
         if ($timeToLoad > config('veer.loadingtime')) {
             \Log::alert('Slowness detected: ' . $timeToLoad . ': ', app('veer')->statistics());
             info('Queries: ', \DB::getQueryLog());
         }
         \Veer\Jobs\TrackingUser::run();
         (new \Veer\Commands\HttpQueueWorkerCommand(config('queue.default')))->handle();
     }
 }
Esempio n. 10
0
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     try {
         $this->bootStore($this->app['App\\Store']);
         $this->bootTheme($this->app['App\\Theme'], $this->app['App\\Store']);
     } catch (QueryException $e) {
         // missing core tables
         if (!\App::runningInConsole()) {
             throw new HttpException(500, "Lavender not installed.");
         }
     } catch (\Exception $e) {
         // something went wrong
         if (!\App::runningInConsole()) {
             throw new HttpException(500, $e->getMessage());
         }
     }
 }
 public function __construct(Migrator $migrator, MigrationRepositoryInterface $repository)
 {
     $commands = [];
     foreach ($this->commands as $command) {
         if ($command == InstallCommand::class) {
             $instance = new $command($repository);
         } else {
             $instance = new $command($migrator);
         }
         $instance->setName('artificer:' . $instance->getName());
         $commands[] = $instance;
     }
     /*
      * Only allow this commands via UI to avoid some inconsistencies
      */
     if (!\App::runningInConsole()) {
         $this->registerCommands($commands);
     }
 }
 /**
  * @param \Illuminate\Contracts\Foundation\Application $app
  */
 public function __construct($app)
 {
     // detect site section and make its service provider and import
     /** @var AppSiteLoaderInterface|AppSiteLoader $className */
     foreach ($this->additionalSectionLoaderClasses as $className) {
         if ($className::canBeUsed()) {
             static::$siteLoader = new $className($this, $app);
             break;
         }
     }
     if (static::$siteLoader === null) {
         if ($this->consoleSectionLoaderClass !== null && \App::runningInConsole()) {
             $className = $this->consoleSectionLoaderClass;
         } else {
             $className = $this->defaultSectionLoaderClass;
         }
         static::$siteLoader = new $className($this, $app);
     }
     parent::__construct($app);
 }
Esempio n. 13
0
 public function boot()
 {
     // If we run `artisan vendor publish --force`, we can overwrite config files;
     // this is user error (most likely, my user error), but it's a major c**k-up so let's catch it
     if (\App::runningInConsole()) {
         $args = $_SERVER['argv'];
         if (!empty($args)) {
             // Are we attempting to run `artisan vendor publish --force`, without the public tag?
             if (in_array('artisan', $args) && in_array('vendor:publish', $args) && (!in_array('--tag=public', $args) || in_array('--tag=config', $args)) && in_array('--force', $args)) {
                 // Require a `--ctrl` flag in order to force a `vendor publish`
                 if (!in_array('--ctrl', $args)) {
                     $message = ['Running `artisan vendor publish --force` will override CTRL config files!', 'If you really wish to do this, please add the flag `--ctrl`.', 'Otherwise, to publish CSS files only, use the argument `--tag=public`.'];
                     $maxlen = max(array_map('strlen', $message));
                     // Nice, http://stackoverflow.com/questions/1762191/how-to-get-the-length-of-longest-string-in-an-array
                     $divider = str_repeat('*', $maxlen);
                     array_unshift($message, $divider);
                     array_push($message, $divider);
                     echo "\n" . implode("\n", $message) . "\n\n";
                     exit;
                 }
             }
         }
     }
     /* Can I put this here? Just check that we have a Ctrl folder, for models and Modules */
     $ctrl_folder = app_path('Ctrl/');
     if (!File::exists($ctrl_folder)) {
         File::makeDirectory($ctrl_folder, 0777, true);
         // See http://laravel-recipes.com/recipes/147/creating-a-directory
     }
     $this->loadViewsFrom(realpath(__DIR__ . '/../views'), 'ctrl');
     $this->setupRoutes($this->app->router);
     // This allows the config file to be published using artisan vendor:publish
     $this->publishes([__DIR__ . '/config/ctrl.php' => config_path('ctrl.php')], 'config');
     // See https://laravel.com/docs/5.0/packages#publishing-file-groups
     // Make sure we have a CtrlModules file:
     $this->publishes([__DIR__ . '/Modules/CtrlModules.php' => $ctrl_folder . '/CtrlModules.php'], 'config');
     // This copies our assets folder into the public folder for easy access, again using artisan vendor:publish
     $this->publishes([realpath(__DIR__ . '/../assets') => public_path('assets/vendor/ctrl')], 'public');
 }
Esempio n. 14
0
 /**
  * Show inspector full screen page and die
  * @return [type] [description]
  */
 public function dd($status = 206, $analizeResponse = false)
 {
     // Try to take these values as soon as posible
     $time = microtime(true);
     $memoryUsage = formatMemSize(memory_get_usage());
     // CLI response
     if (\App::runningInConsole()) {
         $result = $this->collectorMan->getRaw();
         dump($result);
         return;
     }
     // Json respnse
     if (request()->wantsJson()) {
         $title = $status == 206 ? 'DD' : "UNCAUGHT EXCEPTION";
         header("status: {$status}", true);
         header("Content-Type: application/json", true);
         $collectorData = request()->headers->has('laravel-inspector') ? $this->collectorMan->getScripts('inspector', $title, $status) : $this->collectorMan->getPreJson('inspector');
         if ($analizeResponse) {
             // Respond the payload also
             $collectorData = array_merge(json_decode($this->response->getContent(), true), ['LARAVEL_INSPECTOR' => $collectorData]);
         } else {
             $collectorData = ['LARAVEL_INSPECTOR' => $collectorData];
         }
         echo json_encode($collectorData);
         die;
     } else {
         // Fullscreen dd
         // Get collectors bag ready for fullscreen view
         $collectorData = $this->collectorMan->getFs();
         try {
             $view = (string) view('inspector::fullscreen', ['analizeView' => $analizeResponse, 'collectors' => $collectorData, 'memoryUsage' => $memoryUsage, 'time' => round(($time - LARAVEL_START) * 1000, 2)]);
             echo $view;
             die;
         } catch (\Exception $e) {
             dump($e);
             die;
         }
     }
 }
Esempio n. 15
0
 public function id()
 {
     if (app()->runningInConsole()) {
         return null;
     }
     //1. get current host
     $host = $this->host(true);
     //2. see if we already know the site ID from this host in the cache
     $cacheKey = 'site_id_' . $host;
     $siteId = Cache::get($cacheKey);
     //3. if we couldn't find an entry in the cache, find the site ID via the database
     if (empty($siteId)) {
         $siteId = $this->getSiteIdFromDatabase($host);
     }
     //4. throw an exception if we couldn't find the site ID in the database
     if (empty($siteId) && !\App::runningInConsole()) {
         $error = 'Host was not defined as a site on the database level: ' . $host;
         throw new \Exception($error);
     }
     //5. Keep the siteId in the cache!
     $expiresAt = Carbon::now()->addMinutes(10);
     Cache::put($cacheKey, $siteId, $expiresAt);
     return $siteId;
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->publishes([__DIR__ . '/../config/propel.php' => config_path('propel.php')]);
     if (!$this->app->config['propel.propel.runtime.connections']) {
         throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.');
     }
     // load pregenerated config
     if (file_exists(app_path() . '/propel/config.php')) {
         Propel::init(app_path() . '/propel/config.php');
         return;
     }
     // runtime configuration
     /** @var \Propel\Runtime\ServiceContainer\StandardServiceContainer */
     $serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
     $serviceContainer->closeConnections();
     $serviceContainer->checkVersion('2.0.0-dev');
     $propel_conf = $this->app->config['propel.propel'];
     $runtime_conf = $propel_conf['runtime'];
     // set connections
     foreach ($runtime_conf['connections'] as $connection_name) {
         $config = $propel_conf['database']['connections'][$connection_name];
         if (!isset($config['classname'])) {
             if ($this->app->config['app.debug']) {
                 $config['classname'] = '\\Propel\\Runtime\\Connection\\DebugPDO';
             } else {
                 $config['classname'] = '\\Propel\\Runtime\\Connection\\ConnectionWrapper';
             }
         }
         $serviceContainer->setAdapterClass($connection_name, $config['adapter']);
         $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
         $manager->setConfiguration($config + [$propel_conf['paths']]);
         $manager->setName($connection_name);
         $serviceContainer->setConnectionManager($connection_name, $manager);
     }
     $serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']);
     // set loggers
     $has_default_logger = false;
     if (isset($runtime_conf['log'])) {
         foreach ($runtime_conf['log'] as $logger_name => $logger_conf) {
             $serviceContainer->setLoggerConfiguration($logger_name, $logger_conf);
             $has_default_logger |= $logger_name === 'defaultLogger';
         }
     }
     if (!$has_default_logger) {
         $serviceContainer->setLogger('defaultLogger', \Log::getMonolog());
     }
     Propel::setServiceContainer($serviceContainer);
     $command = false;
     if (\App::runningInConsole()) {
         $input = new ArgvInput();
         $command = $input->getFirstArgument();
     }
     // skip auth driver adding if running as CLI to avoid auth model not found
     if ('propel:model:build' !== $command && 'propel' === \Config::get('auth.driver')) {
         $query_name = \Config::get('auth.user_query', false);
         if ($query_name) {
             $query = new $query_name();
             if (!$query instanceof Criteria) {
                 throw new InvalidConfigurationException("Configuration directive «auth.user_query» must contain valid classpath of user Query. Excpected type: instanceof Propel\\Runtime\\ActiveQuery\\Criteria");
             }
         } else {
             $user_class = \Config::get('auth.model');
             $query = new $user_class();
             if (!method_exists($query, 'buildCriteria')) {
                 throw new InvalidConfigurationException("Configuration directive «auth.model» must contain valid classpath of model, which has method «buildCriteria()»");
             }
             $query = $query->buildPkeyCriteria();
             $query->clear();
         }
         \Auth::extend('propel', function (\Illuminate\Foundation\Application $app) use($query) {
             return new PropelUserProvider($query, $app->make('hash'));
         });
     }
 }
Esempio n. 17
0
/*
|--------------------------------------------------------------------------
| Application Error Handler
|--------------------------------------------------------------------------
|
| Here you may handle any errors that occur in your application, including
| logging them or displaying custom views for specific errors. You may
| even register several error handlers to handle different types of
| exceptions. If nothing is returned, the default error view is
| shown, which includes a detailed stack trace during debug.
|
*/
ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_NOTICE);
App::error(function (Exception $exception, $code) {
    Log::error($exception);
    if (App::runningInConsole() && App::environment() !== 'testing') {
        return Response::make($exception);
    }
    if (Input::get('dbg') == 1) {
        return;
    }
    // Here we response invalid request with an error page
    $layout = View::exists('errors.' . $code) ? 'errors.' . $code : 'errors.500';
    $title = $code;
    $errors = trans($exception->getMessage());
    if (App::environment() !== 'local') {
        return View::make($layout, compact('title', 'errors'));
    }
});
/*
|--------------------------------------------------------------------------
Esempio n. 18
0
| Here you may handle any errors that occur in your application, including
| logging them or displaying custom views for specific errors. You may
| even register several error handlers to handle different types of
| exceptions. If nothing is returned, the default error view is
| shown, which includes a detailed stack trace during debug.
|
*/
App::error(function (Exception $exception, $code) {
    Log::error($exception);
    if (!Config::get('app.debug') && !App::runningInConsole()) {
        return Response::view('errors.500', array('code' => $code, 'exception' => $exception), $code);
    }
});
App::fatal(function (Exception $exception) {
    Log::error($exception);
    if (!Config::get('app.debug') && !App::runningInConsole()) {
        return Response::view('errors.500', array('code' => 'Fatal', 'exception' => $exception), 500);
    }
});
/*
|--------------------------------------------------------------------------
| Maintenance Mode Handler
|--------------------------------------------------------------------------
|
| The "down" Artisan command gives you the ability to put an application
| into maintenance mode. Here, you will define what is displayed back
| to the user if maintenance mode is in effect for the application.
|
*/
App::down(function () {
    return Response::view('errors.503', array(), 503);
Esempio n. 19
0
} catch (PDOException $e) {
    try {
        // this is a hack for people who use php artisan serve
        // and have not restarted their server yet, after an
        // install... for homestead users, this shouldn't be executed
        App::make('Devise\\Support\\Installer\\InstallWizard')->refreshEnvironment();
        App::make('Devise\\Pages\\RoutesGenerator')->loadRoutes();
    } catch (PDOException $e) {
        if (in_array($e->getCode(), array("2002", "1044", "1045", "1049", "42S02", "HY000"))) {
            if (App::runningInConsole()) {
                return;
            }
            if (env('DEVISE_INSTALL') != 'ignore') {
                Route::get('/', function () {
                    return Redirect::to("/install/welcome");
                });
                Route::any('{any?}', function () {
                    return Redirect::to("/install/welcome");
                })->where('any', '^((?!install).)*$');
                Route::controller('install', 'Devise\\Support\\Installer\\InstallerController');
                return;
            }
        }
        if (strpos($e->getMessage(), 'Unknown column \'middleware\'') !== false && App::runningInConsole()) {
            // ignoring missing column 'middleware' error on command line
            // allowing users to run "devise:upgrade" without problems
            return;
        }
        throw $e;
    }
}
Esempio n. 20
0
 /**
  * method to set the locale
  *
  * @param string $locale
  * @return \Netson\L4gettext\L4gettext
  * @throws InvalidLocaleException
  */
 public function setLocale($locale)
 {
     // fetch locales list
     $locales = Config::get('l4gettext::locales.list');
     // sanity check
     if (!in_array($locale, $locales)) {
         throw new InvalidLocaleException("The provided locale [{$locale}] does not exist in the list of valid locales [config/locales.php]");
     }
     // set locale in class
     $this->locale = $locale;
     // get localecodeset
     $localecodeset = $this->getLocaleAndEncoding();
     // set environment variable
     if (!putenv('LC_ALL=' . $localecodeset)) {
         throw new EnvironmentNotSetException("The given locale [{$localecodeset}] could not be set as environment [LC_ALL] variable; it seems it does not exist on this system");
     }
     if (!putenv('LANG=' . $localecodeset)) {
         throw new EnvironmentNotSetException("The given locale [{$localecodeset}] could not be set as environment [LANG] variable; it seems it does not exist on this system");
     }
     // set locale - the exception is only thrown in case the app is NOT run from the command line
     // ignoring the cli creates a chicken and egg problem when attempting to fetch the installed locales/encodings,
     // since the ServiceProvider will always attempt to load the locale/encoding before the config files can even be
     // published; thus not allowing the user to change the default settings which should prevent the exception in the first place
     if (!setlocale(LC_ALL, $localecodeset) && !\App::runningInConsole()) {
         throw new LocaleNotFoundException("The given locale [{$localecodeset}] could not be set; it seems it does not exist on this system");
     }
     // save locale to session
     Session::put('l4gettext_locale', $this->locale);
     // return - allow object chaining
     return $this;
 }
Esempio n. 21
0
<?php

use Illuminate\Database\Eloquent\ModelNotFoundException;
//以下内容只在产品环境下有效
$error = function (Exception $exception, $code = 500) {
    Log::error($exception);
    if (App::runningInConsole() || Request::is('api/*')) {
        return Response::json(array('succeed' => 0, 'error_code' => $code, 'error_desc' => '处理失败'));
    } else {
        return View::make($code);
    }
};
// 一般错误
App::error(function ($exception) use($error) {
    return $error($exception, 500);
});
// 404
App::missing(function ($exception) use($error) {
    return $error($exception, 404);
});
// 服务器内部错误
App::fatal(function ($exception) use($error) {
    return $error($exception, 500);
});
//模型未找到
App::error(function (ModelNotFoundException $exception) use($error) {
    return $error($exception, 404);
});
 /**
  * Register propel auth provider.
  *
  * @return void
  */
 protected function registerPropelAuth()
 {
     $command = false;
     if (\App::runningInConsole()) {
         $input = new ArgvInput();
         $command = $input->getFirstArgument();
     }
     // skip auth driver adding if running as CLI to avoid auth model not found
     if ('propel:model:build' === $command) {
         return;
     }
     $query_name = \Config::get('auth.user_query', false);
     if ($query_name) {
         $query = new $query_name();
         if (!$query instanceof Criteria) {
             throw new InvalidConfigurationException("Configuration directive «auth.user_query» must contain valid classpath of user Query. Excpected type: instanceof Propel\\Runtime\\ActiveQuery\\Criteria");
         }
     } else {
         $user_class = \Config::get('auth.model');
         $query = new $user_class();
         if (!method_exists($query, 'buildCriteria')) {
             throw new InvalidConfigurationException("Configuration directive «auth.model» must contain valid classpath of model, which has method «buildCriteria()»");
         }
         $query = $query->buildPkeyCriteria();
         $query->clear();
     }
     \Auth::extend('propel', function (Application $app) use($query) {
         return new Auth\PropelUserProvider($query, $app->make('hash'));
     });
 }
Esempio n. 23
0
<?php

if (App::runningInConsole()) {
    return;
}
// WARNING: you must comment this init route on production
// INIT INIT INIT COMMENT THIS AFTER FIRST USAGE
Route::controller('init', 'InitController');
//route by domain
foreach (Domain::all() as $dcp) {
    Route::group(array('domain' => $dcp['domain']), function () use($dcp) {
        if (!Cookie::get('domain_hash')) {
            Route::get('/', 'PanelController@dcp');
        }
    });
}
Route::get('/', 'HomeController@showHome');
Route::controller('login', 'LoginController');
Route::get('logout', 'LoginController@getLogout');
Route::controller('register', 'RegisterController');
Route::controller('password', 'PasswordController');
// Start of private routes protected with auth
Route::controller('dashboard', 'DashboardController');
Route::get('phone_number/manage/{hash}', 'PhoneNumberController@manage');
Route::get('phone_number/manage/{hash}/add', 'PhoneNumberController@getAdd');
Route::get('phone_number/manage/{hash}/edit/{id}', 'PhoneNumberController@getEdit');
Route::post('phone_number/manage/{hash}/store', 'PhoneNumberController@postStore');
Route::any('phone_number/manage/{hash}/update/{id}', 'PhoneNumberController@update');
Route::get('phone_number/manage/{hash}/delete/{id}', 'PhoneNumberController@getDelete');
Route::any('phone_number/update/{id}', 'PhoneNumberController@update');
Route::any('phone_number/search', 'PhoneNumberController@getIndex');
Esempio n. 24
0
 public function __construct()
 {
     if (!\App::runningInConsole() && Gate::denies('admin')) {
         abort(403);
     }
 }
Esempio n. 25
0
/**
 * Check if we are in the console
 * @return boolean
 */
function zbase_is_console()
{
    return \App::runningInConsole();
}
Esempio n. 26
0
 /**
  * Whether environment is in read only mode.
  *
  * @return bool
  */
 protected function readOnly()
 {
     return !\App::runningInConsole() && (env('HYN_READ_ONLY') && !in_array(Request::ip(), explode(',', env('HYN_READ_ONLY_WHITELIST'))));
 }