apache_conf Laravel - 像老板一样修补(用PsySH)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apache_conf Laravel - 像老板一样修补(用PsySH)相关的知识,希望对你有一定的参考价值。
<?php // ~/.config/psysh/config.php
// Anything not Laravel - let's try to autoload something likely to exist
if (!defined('LARAVEL_START')) {
return [
'defaultIncludes' => [
getcwd().'/vendor/autoload.php',
getcwd().'/bootstrap/autoload.php',
],
];
}
/*
|--------------------------------------------------------------------------
| Laravel magic begins
|--------------------------------------------------------------------------
*/
// Register toRawSql() macro which will get nice, full sql of the query (with bound values)
\Illuminate\Database\Query\Builder::macro('toRawSql', function () {
$bindings = array_map(function ($binding) {
return is_int($binding) || is_float($binding) ? $binding : "'{$binding}'";
}, $this->getBindings());
return vsprintf(str_replace('?', "%s", $this->toSql()), $bindings);
});
/*
|--------------------------------------------------------------------------
| Custom casters (presenters) and aliases registration for PsySH
|--------------------------------------------------------------------------
*/
_Tinker::alias('Carbon\Carbon');
class _Tinker
{
static function castQuery($query)
{
if ($query instanceof \Illuminate\Database\Eloquent\Builder) {
$query = $query->getQuery();
}
return [
'sql' => $query->toSql(),
'bindings' => $query->getBindings(),
'raw' => $query->toRawSql(),
];
}
static function register($path)
{
foreach (glob($path.'/*.php') as $file) {
$class = trim(app()->getNamespace(), '\\') . str_replace([app_path(), '/', '.php'], ['', '\\', ''], $file);
self::alias($class);
}
}
static function alias($class, $alias = null)
{
if (!class_exists($alias = $alias ?: class_basename($class)) && class_exists($class)) {
class_alias($class, $alias);
}
}
}
/*
|--------------------------------------------------------------------------
| Application HTTP requests helper
|--------------------------------------------------------------------------
*/
// Why extending TestCase here? Just because it's sooo easy and consistent across all L versions ;)
class _LocalRequest extends \TestCase
{
function __construct()
{
$this->setUp();
}
function response()
{
return $this->response;
}
function __call($method, $params)
{
return call_user_func_array([$this, $method], $params);
}
}
/*
|--------------------------------------------------------------------------
| Helper functions for common tasks
|--------------------------------------------------------------------------
*/
if (!function_exists('local')) {
function local($uri = null) { return $uri ? (new _LocalRequest)->get($uri) : new _LocalRequest; }
}
if (!function_exists('guzzle')) {
function guzzle($url = null) { return $url ? (new \GuzzleHttp\Client)->get($url) : new \GuzzleHttp\Client; }
}
if (!function_exists('http')) {
function http($url = null) { return guzzle($url); }
}
if (!function_exists('www')) {
function www($url = null) { return guzzle($url); }
}
if (!function_exists('now')) {
function now($timezone = null) { return \Carbon\Carbon::now($timezone); }
}
/*
|--------------------------------------------------------------------------
| Finally let's return PsySH config customizations
|--------------------------------------------------------------------------
*/
return [
'casters' => [
'Illuminate\Database\Eloquent\Builder' => '_Tinker::castQuery',
'Illuminate\Database\Query\Builder' => '_Tinker::castQuery',
],
'defaultIncludes' => [
getcwd().'/.tinker',
],
];
以上是关于apache_conf Laravel - 像老板一样修补(用PsySH)的主要内容,如果未能解决你的问题,请参考以下文章
apache_conf WraOS的Laravel .htaccess
apache_conf Laravel - 像老板一样修补(用PsySH)
apache_conf Laravel .htaccess具有安全性和优化功能