public function accueilAction($id) { $article = new Article(); $article->setTitle('Titre article'); $array = array('brothers' => 'John', 'sisters' => ['Jil', 'Ana'], 'parents' => ['father' => 'Marc', 'mother' => 'Jade']); $names = new Collection($array); while ($name = $names->fetch()) { echo $name->isEven() ? '* ' : ''; if ($name->isCollection()) { echo $name->key() . ' (' . $name->length() . ') : ' . $name->implode(', ') . '<br>'; } else { echo $name->key() . ' (' . $name->length() . ') : ' . $name . '<br>'; } } $user = new User(); $user->setLogin('Grégory'); $tab = ['id' => 1254, 'title' => 'Mon titre', 'author' => $user]; $article->fill($tab); $data = $article->getRecord(); $article->save(); $test = ['test' => '<html>', 'roles' => ['admin' => '<body>', 'user' => ['<truc>', '<machin>']]]; $test = new Collection($test); App::debug($test->toArray()); $this->vars->set('page_title', 'Accueil'); $this->render('index'); }
public function fill(array $array) { foreach ($array as $key => $value) { $method_name = 'set' . App::toCamelCase($key); if (method_exists(get_class($this), $method_name)) { call_user_func_array(array($this, $method_name), array($value)); } } }
public static function connect() { if (self::$translation === null) { self::$translation = new Translation(['bundle' => null, 'theme' => 'sybil', 'domain' => 'debug']); } if (self::$db === null) { $model_path = CORE_SRC . 'ORM/' . Config::$dbms_to_use . '/Model.php'; if (file_exists($model_path)) { require_once $model_path; $class_name = '\\Sybil\\ORM\\' . Config::$dbms_to_use . '\\' . Config::$dbms_to_use; self::$db = $class_name::connect(); return self::$db; } else { if (ENVIRONMENT == 'production') { $this->redirect('unavailable'); } else { App::translate("dbms_file_missing", self::$translation); die; } } } }
/** * Returns a namespace, generated from a bundle name and a model name. * * @param string $bundle_name Bundle name * @param string $model_name Model name (optional) * * @return string The generated namespace */ public function getNamespace($bundle_name, $model_name = null) { if ($model_name == null) { return Config::$app_namespace . '\\' . App::toCamelCase($bundle_name) . 'Bundle\\Model'; } else { return Config::$app_namespace . '\\' . App::toCamelCase($bundle_name) . 'Bundle\\Model\\' . App::toCamelCase($model_name); } }
public function render($view_name = 'index', $escape = true) { $view_path = BUNDLE . $this->route_data->bundle . '/view/' . $view_name . '.html.twig'; if (file_exists($view_path)) { $this->vars->extract(); // Directories where Twig will search for templates. $template_directories = [BUNDLE . $this->route_data->bundle . '/view', APP . 'theme/manager/view', APP . 'theme/' . Config::$theme . '/view']; $loader = new Twig_Loader_Filesystem($template_directories); if (ENVIRONMENT == 'production') { $twig = new Twig_Environment($loader, ['cache' => CACHE . 'view', 'debug' => false, 'autoescape' => $escape]); } else { $twig = new Twig_Environment($loader, ['cache' => false, 'debug' => true, 'autoescape' => $escape]); } TwigFunctions::initFunctions($twig); // Loading custom Twig functions if ($this->store === false) { echo $twig->render($view_name . '.html.twig', $this->vars->toArray()); } else { $this->template = $twig->render($view_name . '.html.twig', $this->vars->toArray()); } } else { if (ENVIRONMENT == 'production') { $this->setError(); } else { $this->translate->setVar('view_path', $view_path); $this->translate->setVar('bundle', $this->route_data->bundle); App::translate("missing_view_file", $this->translate, $this->trans_debug); die; } } }
/* * Application boot file * * Sybil Framework * (c) 2014 Grégory Bellencontre */ namespace Sybil; use Twig_Autoloader; require_once '../vendor/autoload.php'; require_once '../app/Config.php'; // À retirer une fois la classe Config développée require_once '../app/constants.php'; // Là dedans aussi // Session initialization session_name(App::slugify(Config::$app_namespace)); session_start(); // Location and time settings define('LOCALE', !empty($_SESSION['locale']) ? filter_var($_SESSION['locale'], FILTER_SANITIZE_STRING) : Config::$locale); date_default_timezone_set(Config::$timezone); putenv('LC_ALL=' . LOCALE); setlocale(LC_ALL, LOCALE); // Environment definition define('ENVIRONMENT', Config::$environment); Yaml::init(); Twig_Autoloader::register(); // Routes cache settings if (ENVIRONMENT == 'development') { Routing::cache(); } // Request process
public function setPassword($password) { $this->password = App::hash($password); }
public function loadModel($model_name) { $model_path = MODEL . 'model.' . $model_name . '.php'; if (file_exists($model_path)) { require_once $model_path; } else { if (ENVIRONMENT == 'development') { App::debug($this->translation->translate("The model file %model% doesn't exists", $model_path, false, 'sybil', 'debug')); die; } } }