Added Laravel project
This commit is contained in:
108
Laravel/vendor/laravel/tinker/src/ClassAliasAutoloader.php
vendored
Normal file
108
Laravel/vendor/laravel/tinker/src/ClassAliasAutoloader.php
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Tinker;
|
||||
|
||||
use Psy\Shell;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ClassAliasAutoloader
|
||||
{
|
||||
/**
|
||||
* The shell instance.
|
||||
*
|
||||
* @var \Psy\Shell
|
||||
*/
|
||||
protected $shell;
|
||||
|
||||
/**
|
||||
* All of the discovered classes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $classes = [];
|
||||
|
||||
/**
|
||||
* Register a new alias loader instance.
|
||||
*
|
||||
* @param \Psy\Shell $shell
|
||||
* @param string $classMapPath
|
||||
* @return static
|
||||
*/
|
||||
public static function register(Shell $shell, $classMapPath)
|
||||
{
|
||||
return tap(new static($shell, $classMapPath), function ($loader) {
|
||||
spl_autoload_register([$loader, 'aliasClass']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new alias loader instance.
|
||||
*
|
||||
* @param \Psy\Shell $shell
|
||||
* @param string $classMapPath
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Shell $shell, $classMapPath)
|
||||
{
|
||||
$this->shell = $shell;
|
||||
|
||||
$vendorPath = dirname(dirname($classMapPath));
|
||||
|
||||
$classes = require $classMapPath;
|
||||
|
||||
foreach ($classes as $class => $path) {
|
||||
if (! Str::contains($class, '\\') || Str::startsWith($path, $vendorPath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = class_basename($class);
|
||||
|
||||
if (! isset($this->classes[$name])) {
|
||||
$this->classes[$name] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the closest class by name.
|
||||
*
|
||||
* @param string $class
|
||||
* @return void
|
||||
*/
|
||||
public function aliasClass($class)
|
||||
{
|
||||
if (Str::contains($class, '\\')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fullName = isset($this->classes[$class])
|
||||
? $this->classes[$class]
|
||||
: false;
|
||||
|
||||
if ($fullName) {
|
||||
$this->shell->writeStdout("[!] Aliasing '{$class}' to '{$fullName}' for this Tinker session.\n");
|
||||
|
||||
class_alias($fullName, $class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister the alias loader instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unregister()
|
||||
{
|
||||
spl_autoload_unregister([$this, 'aliasClass']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the destruction of the instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->unregister();
|
||||
}
|
||||
}
|
119
Laravel/vendor/laravel/tinker/src/Console/TinkerCommand.php
vendored
Normal file
119
Laravel/vendor/laravel/tinker/src/Console/TinkerCommand.php
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Tinker\Console;
|
||||
|
||||
use Psy\Shell;
|
||||
use Psy\Configuration;
|
||||
use Illuminate\Console\Command;
|
||||
use Laravel\Tinker\ClassAliasAutoloader;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class TinkerCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Artisan commands to include in the tinker shell.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commandWhitelist = [
|
||||
'clear-compiled', 'down', 'env', 'inspire', 'migrate', 'optimize', 'up',
|
||||
];
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'tinker';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Interact with your application';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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'));
|
||||
|
||||
$path = $this->getLaravel()->basePath('vendor/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;
|
||||
}
|
||||
}
|
||||
|
||||
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'],
|
||||
];
|
||||
}
|
||||
}
|
95
Laravel/vendor/laravel/tinker/src/TinkerCaster.php
vendored
Normal file
95
Laravel/vendor/laravel/tinker/src/TinkerCaster.php
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Tinker;
|
||||
|
||||
use Exception;
|
||||
use Symfony\Component\VarDumper\Caster\Caster;
|
||||
|
||||
class TinkerCaster
|
||||
{
|
||||
/**
|
||||
* Application methods to include in the presenter.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $appProperties = [
|
||||
'configurationIsCached',
|
||||
'environment',
|
||||
'environmentFile',
|
||||
'isLocal',
|
||||
'routesAreCached',
|
||||
'runningUnitTests',
|
||||
'version',
|
||||
'path',
|
||||
'basePath',
|
||||
'configPath',
|
||||
'databasePath',
|
||||
'langPath',
|
||||
'publicPath',
|
||||
'storagePath',
|
||||
'bootstrapPath',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get an array representing the properties of an application.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @return array
|
||||
*/
|
||||
public static function castApplication($app)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach (self::$appProperties as $property) {
|
||||
try {
|
||||
$val = $app->$property();
|
||||
|
||||
if (! is_null($val)) {
|
||||
$results[Caster::PREFIX_VIRTUAL.$property] = $val;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing the properties of a collection.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $collection
|
||||
* @return array
|
||||
*/
|
||||
public static function castCollection($collection)
|
||||
{
|
||||
return [
|
||||
Caster::PREFIX_VIRTUAL.'all' => $collection->all(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array representing the properties of a model.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @return array
|
||||
*/
|
||||
public static function castModel($model)
|
||||
{
|
||||
$attributes = array_merge(
|
||||
$model->getAttributes(), $model->getRelations()
|
||||
);
|
||||
|
||||
$visible = array_flip(
|
||||
$model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden())
|
||||
);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach (array_intersect_key($attributes, $visible) as $key => $value) {
|
||||
$results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL : Caster::PREFIX_PROTECTED).$key] = $value;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
40
Laravel/vendor/laravel/tinker/src/TinkerServiceProvider.php
vendored
Normal file
40
Laravel/vendor/laravel/tinker/src/TinkerServiceProvider.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Tinker;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Tinker\Console\TinkerCommand;
|
||||
|
||||
class TinkerServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('command.tinker', function () {
|
||||
return new TinkerCommand;
|
||||
});
|
||||
|
||||
$this->commands(['command.tinker']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['command.tinker'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user