public static function t($string, array $replace_pairs = array()) { isset(static::$current) or static::set(Request::get()->locale()) or static::set(self::REFERENCE); if (static::$current !== static::REFERENCE) { foreach (App::all('Sedra\\Locale\\TranslationProvider') as &$translation_provider) { $translation = $translation_provider->get_translation($string, static::$current); if ($translation) { $string = $translation; break; } } # else : Not found, not translated } # Transform arguments before inserting them. foreach ($replace_pairs as $key => &$value) { switch ($key[0]) { case '@': default: # XXX $replace_pairs[$key] = htmlentities($value, ENT_QUOTES, 'UTF-8'); $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); break; case '!': # Do not escape the string } } return strtr($string, $replace_pairs); }
public static function process(Request $request) { try { if (!$request->query) { if (static::option('default_route')) { $route = static::get_route(static::option('default_route')); return $route->process($request); } } else { foreach (App::all('Sedra\\Router\\RouteProvider') as $controller) { $routes = $controller->get_routes(); foreach ($routes as $route_name => $route) { $arguments = array(); if ($route->match($request, $arguments)) { $request->route = $route; $request->arguments = $arguments; return $route->process($request, $arguments); } } } } # Route not found throw new RouteNotFoundException($request); } catch (\Exception $e) { if ($request instanceof HTTPRequest) { return new HTTPErrorResponse($request, $e); } else { throw $e; } } }
public static function factory($view_name, array $data = array()) { foreach (App::all('Sedra\\View\\TemplateEngineProvider') as $engine_provider) { try { $template_engine = $engine_provider->get_template_engine(); $view = $template_engine->factory($view_name, $data); if ($view instanceof View) { return $view; } else { # Invalid behavior... Should return a View or throw ViewNotFoundException throw new ViewException(); } } catch (ViewNotFoundException $e) { continue; } } throw new ViewNotFoundException($view_name, $data); }
<?php $loader = (require __DIR__ . '/vendor/autoload.php'); $loader->add('Custom\\', __DIR__); use Sedra\App; use Sedra\Locale; use Sedra\Router; use Sedra\Request; use Sedra\Response; # Enable custom locales Locale::enable(array('fr_BE', 'en_US')); # Setup the router Router::setup(array('rewrite' => true)); # Configure & register the Sedra CMS and core controllers App::register(new Sedra\Controller\i18n()); App::register(new Sedra\Controller\Admin()); App::register(new Sedra\Controller\Sedra(array('site_name' => 'My amazing website'))); # Add custom controllers App::register(new Sedra\Controller\Blog()); App::register(new Custom\Controller\MyPhotoGallery()); # Process the request App::process();