Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit

Permalink
Replace AppHelper to OverrideHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
miyacorata committed May 8, 2020
1 parent b0eb78c commit 0aeec38
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
54 changes: 54 additions & 0 deletions app/Console/Commands/BootstrapAutoloadCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class BootstrapAutoloadCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bootstrap:autoload';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Load OverrideHelper';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$autoloadPath = base_path('vendor/autoload.php');
$helperPath = app_path('Helpers/OverrideHelper.php');

// オートローダーのファイル内容を読み込む
$before = file_get_contents($autoloadPath);

// 先に自作ヘルパファイルを一番最初に読み込むようにする
$after = str_replace('<?php' . PHP_EOL, "<?php require_once '$helperPath';" . PHP_EOL, $before);

// オートローダーを上書きする
file_put_contents($autoloadPath, $after);

return 0;
}
}
4 changes: 2 additions & 2 deletions app/Helpers/AppHelper.php → app/Helpers/OverrideHelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
if(!function_exists('__fb')){
if(!function_exists('__')){
/**
* 翻訳関数(空文字列時のフォールバック付)
*
Expand All @@ -8,7 +8,7 @@
* @param string|null $locale
* @return string|array|null
*/
function __fb($key = null, $replace = [], $locale = null)
function __($key = null, $replace = [], $locale = null)
{
if (is_null($key)) {
return $key;
Expand Down
1 change: 1 addition & 0 deletions app/Providers/HelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class HelperServiceProvider extends ServiceProvider
public function register()
{
foreach(glob(app_path().'/Helpers/*.php') as $file){
if(strpos($file ,'OverrideHelper.php') !== FALSE) continue;
require_once $file;
}
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
"@php artisan package:discover --ansi",
"@php artisan bootstrap:autoload"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
Expand Down

0 comments on commit 0aeec38

Please # to comment.