Constructive description here
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) <Taylor Otwell>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<p align="center"><img src="https://laravel.com/assets/img/components/logo-tinker.svg"></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/laravel/tinker"><img src="https://travis-ci.org/laravel/tinker.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/laravel/tinker"><img src="https://poser.pugx.org/laravel/tinker/d/total.svg" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel/tinker"><img src="https://poser.pugx.org/laravel/tinker/v/stable.svg" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel/tinker"><img src="https://poser.pugx.org/laravel/tinker/license.svg" alt="License"></a>
|
||||
</p>
|
||||
|
||||
## Introduction
|
||||
|
||||
Laravel Tinker is a powerful REPL for the Laravel framework.
|
||||
|
||||
## Installation
|
||||
|
||||
To get started with Laravel Tinker, simply run:
|
||||
|
||||
composer require laravel/tinker
|
||||
|
||||
Next, register the `Laravel\Tinker\TinkerServiceProvider` in your `config/app.php` file:
|
||||
|
||||
```php
|
||||
'providers' => [
|
||||
// Other service providers...
|
||||
|
||||
Laravel\Tinker\TinkerServiceProvider::class,
|
||||
],
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
From your console, execute the `php artisan tinker` command.
|
||||
|
||||
## License
|
||||
|
||||
Laravel Tinker is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "laravel/tinker",
|
||||
"description": "Powerful REPL for the Laravel framework.",
|
||||
"keywords": ["tinker", "repl", "psysh", "laravel"],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Taylor Otwell",
|
||||
"email": "taylor@laravel.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"illuminate/console": "~5.1",
|
||||
"illuminate/contracts": "~5.1",
|
||||
"illuminate/support": "~5.1",
|
||||
"psy/psysh": "0.7.*|0.8.*",
|
||||
"symfony/var-dumper": "~3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0|~5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Laravel\\Tinker\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"suggest": {
|
||||
"illuminate/database": "The Illuminate Database package (~5.1)."
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Laravel\Tinker\Console;
|
||||
|
||||
use Psy\Shell;
|
||||
use Psy\Configuration;
|
||||
use Illuminate\Console\Command;
|
||||
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 fire()
|
||||
{
|
||||
$this->getApplication()->setCatchExceptions(false);
|
||||
|
||||
$config = new Configuration;
|
||||
|
||||
$config->getPresenter()->addCasters(
|
||||
$this->getCasters()
|
||||
);
|
||||
|
||||
$shell = new Shell($config);
|
||||
$shell->addCommands($this->getCommands());
|
||||
$shell->setIncludes($this->argument('include'));
|
||||
|
||||
$shell->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
@@ -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
@@ -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