getApplication()->setCatchExceptions(false); $config = new Configuration([ 'updateCheck' => 'never', ]); $config->getPresenter()->addCasters( $this->getCasters() ); $shell = new Shell($config); $shell->addCommands($this->getCommands()); $shell->setIncludes($this->argument('include')); if (isset($_ENV['COMPOSER_VENDOR_DIR'])) { $path = $_ENV['COMPOSER_VENDOR_DIR']; } else { $path = $this->getLaravel()->basePath().DIRECTORY_SEPARATOR.'vendor'; } $path .= '/composer/autoload_classmap.php'; $loader = ClassAliasAutoloader::register($shell, $path); try { $shell->run(); } finally { $loader->unregister(); } } /** * Get artisan commands to pass through to PsySH. * * @return array */ protected function getCommands() { $commands = []; foreach ($this->getApplication()->all() as $name => $command) { if (in_array($name, $this->commandWhitelist)) { $commands[] = $command; } } foreach (config('tinker.commands', []) as $command) { $commands[] = $this->getApplication()->resolve($command); } return $commands; } /** * Get an array of Laravel tailored casters. * * @return array */ protected function getCasters() { $casters = [ 'Illuminate\Support\Collection' => 'Laravel\Tinker\TinkerCaster::castCollection', ]; if (class_exists('Illuminate\Database\Eloquent\Model')) { $casters['Illuminate\Database\Eloquent\Model'] = 'Laravel\Tinker\TinkerCaster::castModel'; } if (class_exists('Illuminate\Foundation\Application')) { $casters['Illuminate\Foundation\Application'] = 'Laravel\Tinker\TinkerCaster::castApplication'; } return $casters; } /** * Get the console command arguments. * * @return array */ protected function getArguments() { return [ ['include', InputArgument::IS_ARRAY, 'Include file(s) before starting tinker'], ]; } }