前回質問に引き続き、現在も「booked」という予約管理システムのオープンソースの改修をしています。
今度はデータベースからデータを取得して格納するために、ファイルを一つ追加しました。
そのファイルは以下となります(今回あまり中身は関係ないかもしれません)
PHP
1<?php 2require_once(ROOT_DIR . 'lib/Database/Commands/namespace.php'); 3 4interface IComment2Repository 5{ 6 /** 7 * @return array[] 8 */ 9 public function GetAll(); 10} 11 12class Comment2Repository implements IComment2Repository 13{ 14 /** 15 * @var DomainCache 16 */ 17 private $_cache; 18 19 public function __construct() 20 { 21 $this->_cache = new DomainCache(); 22 } 23 24 public function GetComment2List() 25 { 26 $comment2Ary = array(); 27 28 $reader = ServiceLocator::GetDatabase()->Query(new GetComment2ListCommand()); 29 while ($row = $reader->GetRow()) { 30 31 $comment2Ary = array($row[ColumnNames::TEST_A]=>$row[ColumnNames::TEST_B]); 32 } 33 34 $reader->Free(); 35 36 return $comment2Ary; 37 } 38} 39
このファイルを、別ファイルから読み込みたいというのが今回悩んでいるところです。
(読み込み部分は下記)
PHP
1protected function LoadInitializerFactory() 2 { 3 $userRepository = new UserRepository(); 4 $comment2Repository = new Comment2Repository(); // コイツを読み込みたい・・・ 5 return new ReservationInitializerFactory( 6 new ScheduleRepository(), $userRepository, new ResourceService(new ResourceRepository(), 7 $this->permissionServiceFactory->GetPermissionService(), 8 new AttributeService(new AttributeRepository()), 9 $userRepository, 10 new AccessoryRepository()), 11 new ReservationAuthorization(AuthorizationServiceFactory::GetAuthorizationService()), 12 $comment2Repository 13 ); 14 }
こんな感じで new してみたのですが、案の定 ClassNotFoundExceptionが出てしまいました。↓
Uncaught exception: Error: Class 'Comment2Repository' not found in /var/www/booked/Pages/Reservation/ReservationPage.php:401
また、基本的には原因コードの上に記載してある、 UserRepository() を真似しているのですが、
こいつが読み込まれている? namespace.php に同じように以下のように記述をすると、
PHP
1require_once(ROOT_DIR . 'Domain/Access/UserRepository.php'); 2require_once(ROOT_DIR . 'Domain/Access/Comment2Repository.php');
今度は開発サーバーが動かなくなってしまいました・・・。
↓ その時の画像
パスやファイル名などは合っているはずなのですが、オープンソースのPHPに新しいファイルは追加できないのでしょうか・・・(そんなはずないと思うんですが。。。)
それとも新しいファイルを読み込む際には namespace.phpに読み込み先を記述するだけでは足りない?のでしょうか・・・
お時間ある方で、もしお心当たりがある方いらっしゃいましたらご助力頂けますと幸いです。
また、足りない情報などがあれば追記しますのでお申し付け下さい。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。