PHP code example of jetwaves / edit-array-in-file
1. Go to this page and download the library: Download jetwaves/edit-array-in-file library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jetwaves / edit-array-in-file example snippets
$editor->where('aliases',[], Editor::TYPE_KV_PAIR)
->insert("'JWTAuth' => Tymon\\JWTAuth\\Facades\\JWTAuth::class".PHP_EOL)
->save()->flush();
use Jetwaves\EditArrayInFile\Editor;
$editor = new Editor('testSource/app.php');
$targetArray = editor->where('aliases',[], Editor::TYPE_KV_PAIR)->get();
echo ' '.method.'() line:'.line.' targetArray = '.print_r(targetArray, true);
() line:10 $targetArray = Array
(
[0] => 'aliases' => [
// ATTENTION: there is PHP_EOL in the end of these lines who are invisible.
[1] =>
[2] => 'App' => Illuminate\Support\Facades\App::class,
[3] => 'Artisan' => Illuminate\Support\Facades\Artisan::class,
[4] =>
[5] => ],
)
$editor->where('aliases',[], Editor::TYPE_KV_PAIR);
$editor->insert("'JWTAuth' => Tymon\\JWTAuth\\Facades\\JWTAuth::class".PHP_EOL);
$editor->save()->flush();
return [
'log' => env('APP_LOG', 'single'),
'log_level' => env('APP_LOG_LEVEL', 'debug'),
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
],
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class // <====== HERE IS THE INSERTED LINE
],
];
$val = $editor->where('aliases',[], Editor::TYPE_KV_PAIR)
->find('App', Editor::FIND_TYPE_KEY_ONLY);
target key `s val = Illuminate\Support\Facades\App::class
$editor->where('aliases',[], Editor::TYPE_KV_PAIR)
->find('JWTAuth', Editor::FIND_TYPE_ALL);
$editor->delete()->save()->flush();
$editor = new Editor('testSource/Kernel.php');
$targetArray = $editor->where('$routeMiddleware',[], Editor::TYPE_VARIABLE)->get();
echo ' '.__method__.'() line:'.__line__.' $targetArray = '.print_r($targetArray, true);
() line:26 $targetArray = Array
(
[0] => protected $routeMiddleware = [
// ATTENTION: there is PHP_EOL in the end of these lines who are invisible.
[1] => 'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
[2] => 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
[3] => 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
[4] => 'can' => \Illuminate\Auth\Middleware\Authorize::class,
[5] => 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
[6] => 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
[7] => 'jwt.auth' => \App\Http\Middleware\VerifyJWTToken::class
[8] => ];
)
$editor->where('$routeMiddleware',[], Editor::TYPE_VARIABLE);
$editor->insert("'jetwaves.auth' => \\App\\Ssq\\TestMiddleware\\VerifyJWTToken::class".PHP_EOL);
$editor->save()->flush();
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
* These middleware may be assigned to groups or used individually.
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'jwt.auth' => \App\Http\Middleware\VerifyJWTToken::class,
'jetwaves.auth' => \App\Ssq\TestMiddleware\VerifyJWTToken::class // <====== HERE IS THE INSERTED LINE
];
}
$editor->where('$routeMiddleware',[], Editor::TYPE_VARIABLE)
->find('bindings', Editor::FIND_TYPE_KEY_ONLY);
target key `s val = \Illuminate\Routing\Middleware\SubstituteBindings::class
$editor->where('$routeMiddleware',[], Editor::TYPE_VARIABLE)
->find('auth.basic', Editor::FIND_TYPE_ALL)
->delete()->save()->flush();