mapping($config); $this->parseStorage($config); $this->parseEvents($config); parent::__construct(); } /** * @param ConfigProvider $config * @return void */ public function mapping(ConfigProvider $config): void { $this->container->bind(LoggerInterface::class, new StdoutLogger()); foreach ($config->get('mapping', []) as $interface => $class) { $this->container->set($interface, $class); } } /** * @param ConfigProvider $config * @return void * @throws InitException */ public function parseStorage(ConfigProvider $config): void { $storage = $config->get('storage', 'storage'); if (!str_contains($storage, APP_PATH)) { $storage = APP_PATH . $storage . '/'; } if (!is_dir($storage)) { mkdir($storage, 0777, true); } if (!is_dir($storage) || !is_writeable($storage)) { throw new InitException("Directory $storage does not have write permission"); } } /** * @param ConfigProvider $config * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws Exception */ public function parseEvents(ConfigProvider $config): void { $events = $config->get('events', []); foreach ($events as $key => $value) { if (is_string($value)) { $value = $this->container->get($value); if (!($value instanceof EventInterface)) { throw new Exception("Event listen must implement " . EventInterface::class); } $value = [$value, 'process']; } $this->provider->on($key, $value, 0); } } }