/** * Required parameters: * from,to,subject,body_html,body_plain * * Optional parameters: * cc * * @param array $emailParameters */ public function sendEmail($emailParameters) { $email = \Swift_Message::newInstance(); $email->setSubject($emailParameters["subject"])->setFrom($emailParameters["from"])->setTo($this->debugMail == null && Application::isDevelopmentEnv() ? $emailParameters["to"] : $this->debugMail)->setBody($emailParameters["body_html"], 'text/html'); if (isset($emailParameters["cc"])) { $email->setCc($emailParameters["cc"]); } $email->addPart($emailParameters["body_plain"], 'text/plain'); $this->mailer->send($email); }
/** * Translator constructor. * @param array $configuration */ public function __construct($configuration) { // Konfiguráció betöltése $this->configuration = $configuration; //Aktuális nyelv kiválasztása a stratégiától függően switch ($this->configuration["strategy"]) { case Translator::STRATEGY_ONLY_COOKIE: if (!isset($this->configuration["cookie_set_url"])) { throw new \InvalidArgumentException("You must provide 'cookie_set_url' parameter in case of STRATEGY_ONLY_COOKIE"); } // Locale beállítása $locale = $this->loadLocaleFromCookie(); break; case Translator::STRATEGY_ONLY_URL: // Itt jelenleg nem kell csinálni semmit, mert a language router mindent elintéz, majd beállítja a // a megfelelő helyen $locale = $configuration["fallbackLocales"][0]; break; case Translator::STRATEGY_COOKIE_AND_URL: // Locale beállítása $locale = $this->loadLocaleFromCookie(); break; default: $locale = $configuration["fallbackLocales"][0]; } //Symfony-s translator inicilaizálása $this->translator = new \Symfony\Component\Translation\Translator($locale); $this->translator->setFallbackLocales($this->configuration["fallbackLocales"]); //Loader és források inicializálás if (Application::isDevelopmentEnv()) { $format = $this->configuration["loader"]["dev"]; } else { $format = $this->configuration["loader"]["prod"]; } $this->translator->addLoader($format, $this->loaderFactory($format)); foreach ($this->configuration["resources"] as $locale => $resources) { foreach ($resources as $resource) { $this->translator->addResource($format, $resource, $locale); } } }
/** * Betölti a twigbe az általunk definiált függvényeket. */ private function initializeBaseTwigFunction() { // Development-e a környezet $is_dev = new \Twig_SimpleFunction('is_dev', function () { return Application::isDevelopmentEnv(); }); $this->twig->addFunction($is_dev); /* * A további twig függvényeket az átláthatóság szempontjából ide tegyük. Célszerű amúgy a Service providerekben * extendelni a twiget. */ }
public function __construct($status, $content = null) { parent::__construct(Application::isDevelopmentEnv() && $content != null ? $content : Response::$statusTexts[$status], $status); }
/** * Alkalmazás indítása * @param ApplicationConfiguration $configuration * @throws HttpAccessDeniedException */ public function run(ApplicationConfiguration $configuration) { try { if (!$configuration) { throw new HttpInternalErrorException("Missing configuration"); } $configuration->initializeApplication($this); //Csekkolni kell, hogy kell-e erőltetni a https-t if ($this->environment["force_https"] && $_SERVER['HTTPS'] != "on") { $this->redirectHttps(); return; } $httpMethod = $_SERVER['REQUEST_METHOD']; $uri = $_SERVER['REQUEST_URI']; //Jogosultság ellenőrzése, ha van definiálva security $security = self::Security(); if ($security != null && !$security->checkPermissions($uri)) { throw new HttpAccessDeniedException(); } //Routeból lekérdezni, hogy mit kell futtatni $router = self::Router(); $routingResult = $router->findRoute($httpMethod, $uri); $controllerParts = explode("::", $routingResult["handler"]); $controllerName = $controllerParts[0]; $controllerMethod = $controllerParts[1]; if ($controllerName === "Translator") { $translator = Application::Translator(); $result = $translator->{$controllerMethod}($routingResult["params"]); } else { //Megfelelő controller betöltése if (!$this->loadController($controllerName) && $controllerName != "Translator") { throw new HttpInternalErrorException($controllerName . " has been not found!"); } //Futtatás $controllerFullName = $this->environment["controller_namespace"] . $controllerName; $controller = new $controllerFullName(); $result = $controller->{$controllerMethod}($routingResult["params"]); } //Eredmény printelése print $result; return; } catch (HttpException $e) { $handler = $this->callableErrorHandler; print $handler($e); } catch (\Exception $e) { print "Unhandled exception!\n"; if (Application::isDevelopmentEnv()) { print $e->getMessage() . "\n"; print str_replace("#", "<br>#", $e->getTraceAsString()); } } }