/** * @param string $name * @return mixed|void */ public function __get($name) { try { return parent::__get($name); } catch (MissingPropertyException $e) { $namespaceTable = 'App\\Tables'; $app = Config::get('app'); if ($app && $app->namespace && isset($app->namespace['table'])) { $namespaceTable = $app->namespace['table']; } return $this->loadTable($namespaceTable . '\\' . ucfirst($name) . 'Table'); } }
/** * Permet de faire le rendu de ce que l'on a donné * * @return string Le rendu à envoyer */ public function render() { $this->file = str_replace('.', '/', $this->file); $app = Config::get('app'); $views = __DIR__ . '/../../../public/views'; $cacheViews = __DIR__ . '/../../../bin/cache/views'; if ($app && $app->folders) { if (isset($app->folders['views'])) { $views = $app->folders['views']; } if (isset($app->folders['cache']) && isset($app->folders['cache']['views'])) { $cacheViews = $app->folders['cache']['views']; } } $blade = new BladeInstance($views, $cacheViews); return $blade->render($this->file, $this->fields); }
/** * Test de la facade */ public function testFacadeConfig() { $configManager = ConfigManager::getInstance(); $this->assertCount(0, $configManager->configs); Config::add(__DIR__ . '/../Test/test.php'); $this->assertCount(1, $configManager->configs); Config::add(__DIR__ . '/../Test/test2.php'); $this->assertCount(2, $configManager->configs); Config::add(__DIR__ . '/../Test/test.php'); $this->assertCount(2, $configManager->configs); Config::add(__DIR__ . '/../Test/test2.php'); $this->assertCount(2, $configManager->configs); $this->assertTrue(Config::exist('test')); $this->assertTrue(Config::exist('test2')); $this->assertFalse(Config::exist('test3')); $this->assertEquals('Test\\Table', Config::get('test')->namespace['table']); $this->assertNull(Config::get('test3')); $this->assertNull(Config::get('test')->unknown); }
private function loadRoutes() { $path = realpath(__DIR__ . '/../../bin/routes'); $configFolder = Config::get('folder'); if ($configFolder) { $routePath = $configFolder->routes; if ($routePath && file_exists($routePath)) { $path = $routePath; } } $rdi = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); $rit = new RecursiveIteratorIterator($rdi); foreach ($rit as $file) { if ($file->getExtension() === 'php') { $pathFile = $file->getRealPath(); require "{$pathFile}"; } } }
/** * Lance le router et appel les middlewares et le controller */ public function run() { $path = realpath(__DIR__ . '/../../bin/routes'); $configFolder = Config::get('folder'); if ($configFolder) { $routePath = $configFolder->routes; if ($routePath && file_exists($routePath)) { $path = $routePath; } } $rdi = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); $rit = new RecursiveIteratorIterator($rdi); foreach ($rit as $file) { if ($file->getExtension() === 'php') { $pathFile = $file->getRealPath(); require "{$pathFile}"; } } $method = Request::method(); $routeReturn = !Request::isCLI(); $route = Router::parse(RequestManager::getInstance()->url, $method, $routeReturn); if ($route instanceof Route) { echo $route->run(); } }
} function post($base = []) { $post = Session::get('post'); Session::unset('post'); $post = empty($post) ? [] : $post; $post = array_merge($base, $post); return $post; } try { $app = new Application(); $app->initConfig(); $app->initDatabase(); $app->initCookies(); $app->initHttp(); $app->initLang(); if (Config::get('app')->debug) { $files = glob(Config::get('folder')->cache['views'] . '/*'); // get all file names foreach ($files as $file) { // iterate files if (is_file($file)) { unlink($file); // delete file } } } $app->run(); } catch (Exception $e) { exit($e->getMessage()); }
/** * @param string $entityClassName * @return string Le namespace complet de l'entité */ private function getEntityNamespace($entityClassName) { if (empty($entityClassName)) { $entityClassName = $this->entityName; } $entityNamespace = 'App\\Entitites'; $nsp = Config::get('namespace'); if ($nsp) { $valueEntityNamespace = $nsp->entities; if ($valueEntityNamespace) { $entityNamespace = $valueEntityNamespace; } } return $entityNamespace . '\\' . str_replace($entityNamespace . '\\', '', $entityClassName); }