2014-12-24 2 views
7

라라벨의 도우미 기능은 if (! function_exists('xx'))입니다.작곡가 : 자동 로딩 _ 파일 요구 사항을 지정하십시오.

autoload_files의 순서를 지정할 수 있으며 Kint.class.php 앞에 helpers.php이 있어야합니까?

return array( 
    $vendorDir . '/laravel/framework/src/Illuminate/Support/helpers.php', 
    $vendorDir . '/raveren/kint/Kint.class.php', 
); 
+0

여기 내 modify_autoload.php입니다 이? 나는 같은 문제에 직면하고있다 ... –

+0

아직 ........ –

답변

0

필자는 여러 가지 방법으로 내 헬퍼를 자동로드에 추가하고 Larvel 헬퍼를 먼저로드하여 테스트했습니다.

내 솔루션은 공급 업체의 자동로드 전에 사용자의 도우미 기능을 포함시키는 것입니다.

function camel_case($value) 
{ 
    return 'MY_OWN_CAMEL_CASE'; 
} 
0

이 정말 불쾌한 문제 :

나는 당신은 당신의 도우미 함수를 정의 할 수 있으며, public 폴더에 index.php 파일에 헬퍼 파일 내부에

//my extra line 
require_once __DIR__.'/../app/helpers.php'; 

//this is laravel original code 
//I make sure to include before this line 

require __DIR__.'/../vendor/autoload.php'; 

그것을했다. https://github.com/composer/composer/issues/6768

"require"또는 "require"클래스 중 하나보다 먼저 사용자 지정 "파일"을로드 할 수 있도록 자동 로딩 작업의 순서를 지정하는 방법이 있어야합니다. -dev "섹션; 벤더 내부에서 타사 패키지를 편집해야하는 솔루션은 해킹 일 뿐이지 만 현재로서는 다른 좋은 대안이 없다고 생각합니다.

필자가 제공 할 수있는 가장 좋은 점은 스크립트를 사용하여 vendor/autoload.php를 수정하여 autoload 클래스가 포함되기 전에 파일을 강제로 포함시키는 것입니다.

<?php 
/** 
* Updates the vendor/autoload.php so it manually includes any files specified in composer.json's files array. 
* See https://github.com/composer/composer/issues/6768 
*/ 
$composer = json_decode(file_get_contents('composer.json')); 

$files = (property_exists($composer, 'files')) ? $composer->files : []; 

if (!$files) { 
    print "No files specified -- nothing to do.\n"; 
    exit; 
} 

$patch_string = ''; 
foreach ($files as $f) { 
    $patch_string .= "require_once __DIR__ . '/../{$f}';\n"; 
} 
$patch_string .= "require_once __DIR__ . '/composer/autoload_real.php';"; 

// Read and re-write the vendor/autoload.php 
$autoload = file_get_contents(__DIR__ . '/vendor/autoload.php'); 
$autoload = str_replace("require_once __DIR__ . '/composer/autoload_real.php';", $patch_string, $autoload); 

file_put_contents(__DIR__ . '/vendor/autoload.php', $autoload); 

당신은 수동으로 실행할 수 있습니다, 또는 작곡가가 composer.json 스크립트에 추가하여 실행할 수 있습니다 : 당신이에 대한 해결책을 찾았나요

{ 
// ... 
    "scripts": { 
    "post-autoload-dump": [ 
     "php modify_autoload.php" 
    ] 
    } 
// ... 
} 
관련 문제