@Elbakidze

Не получается исправить ошибку, что делать?

Здравствуйте, будьте добры, помогите исправить ошибку:
Fatal error: Uncaught Error: Call to a member function add() on null in C:\OSPanel\domains\cmse.ru\engine\cms.php:24 Stack trace: #0 C:\OSPanel\domains\cmse.ru\engine\bootstrap.php(19): engine\cms->run() #1 C:\OSPanel\domains\cmse.ru\index.php(2): require_once('C:\\OSPanel\\doma...') #2 {main} thrown in C:\OSPanel\domains\cmse.ru\engine\cms.php on line 24

cms.php
<?php
namespace engine;
class cms{
  /**
   *
   * @var [type]
   */
  private $di;
  public $router;
/**
 * [_construct description]
 * @param  [type] $di [description]
 * @return [type]     [description]
 */
public function _construct($di){
$this->di = $di;
$this->router = $this->di->get('router');
}
/**
 * Run cms
 */
public function run(){

$this->router->add('home', '/', 'HomeController:index');

print_r($this->di);
}
}
 ?>

bootstrap.php
<?php

require_once __DIR__. '/../vendor/autoload.php';
use engine\cms;
use engine\DI\di;

try {

$di = new DI();

$services = require __DIR__ . '/config/service.php';
// init services
foreach ($services as $service) {
  $provider = new $service($di);
  $provider->init();
}

$cms = new cms($di);
$cms-> run();
} catch (\ErrorException $e){
  echo $e -> getMessage();
}
?>

index.php
<?php
require_once 'engine/bootstrap.php';
?>

di.php
<?php
namespace engine\DI;
class DI {
  /**
  * @var array
  */
  private $container = [];
  /**
   * @param $key
   * @param $value
   * @return $this
   */
  public function set($key, $value){
  $this->conteiner[$key] = $value;
  return $this;
  }
/**
* @param $key
* @return $mixed
 */
  public function get($key)
  {
    return $this->has($key);
  }
  /**
   * [has description]
   * @param  [type]  $key [description]
   * @return boolean      [description]
   */
  public function has($key){
  return isset($this->$container[$key])? $this->$container[$key] : null;

  }

}

?>

service.php
<?php
return [
engine\service\database\provider::class,
engine\service\router\provider::class,
];

 ?>

  • Вопрос задан
  • 135 просмотров
Пригласить эксперта
Ответы на вопрос 1
@heahoh
Full stackoverflow developer
Как у вас в Di объект добавляются сервисы?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы