I持って次のような構造どのようにsymfonyのクラスローダを使用する
API
共通
設定
ドキュメント
スクリプト
ベンダー
私はあなたが作曲ROOTDIR /ベンダーのフォルダの下にあるすべてのものを置く知っているかもしれませんが
<?php
require_once BASE_DIR . 'vendor/autoload.php';
require_once BASE_DIR . 'vendor/symfony/class-loader/ClassLoader.php';
use Symfony\ClassLoader\ClassLoader;
$loader = new \ClassLoader();
// to enable searching the include path (eg. for PEAR packages)
$loader->setUseIncludePath(true);
// ... register namespaces and prefixes here - see below
$loader->register();
// register a single namespaces
$loader->addPrefix('CCP', BASE_DIR . 'common/ccp/');
// cache files locations
require_once BASE_DIR . 'vendor/symfony/class-loader/ApcClassLoader.php';
// sha1(__FILE__) generates an APC namespace prefix
$cachedLoader = new ApcClassLoader(sha1(__FILE__), $loader);
// register the cached class loader
$cachedLoader->register();
// deactivate the original, non-cached loader if it was registered previously
$loader->unregister();
が含まれている共通/ PHP/autoload.php下のカスタムオートローダーを置きます。
Error I get is Fatal error: Uncaught Error: Class 'ClassLoader' not found in ROOTDIR/common/php/autoload.php:7
私は共通の下で私のカスタムクラスをロードしようとUPDATE/CCPは、それがロードされません。クラスの
Fatal error: Uncaught Error: Class 'CCP\Notification' not found in ROOTDIR/scripts/cli-test-email.php:12
内容
<?php
namespace CCP
class Notification{
...
}
UPDATE 2
マイスクリプトscript
フォルダの下にあります。 use
を追加しても、エラーは発生しませんが、エコーやエラーが発生しても何も起こりません。 use
を削除すると、クラスNotification
が見つかりません。この
#!/opt/SP/php-7.0.10/bin/php -q
<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);
echo "before use";
use CCP/Notification;
echo "after use";
$notification = new Notification();
print_r($notification);
$notification->emailTest();
'$ loader = new Symfony \ Component \ ClassLoader \ ClassLoader' – Federkun
なぜ' Symfony \ Component \ ClassLoader \ 'をインクルードする必要がありますか? – shorif2000
名前空間の使い方とpsr-0/4の意味 – Federkun