Example of usage use Bluz\Proxy\Translator; echo Translator::translate('message id');
See also: Instance::translate()
See also: Instance::translatePlural()
Author: Anton Shevchuk
Inheritance: use trait ProxyTrait
Ejemplo n.º 1
0
 /**
  * Denied access
  * @param ForbiddenException $exception
  * @return \Bluz\Controller\Controller|null
  */
 public function forbidden(ForbiddenException $exception)
 {
     if (AuthProxy::getIdentity()) {
         $message = Translator::translate("You don't have permissions to access this page");
     } else {
         $message = Translator::translate("You don't have permissions, please sign in");
     }
     // for AJAX and API calls (over JSON)
     $jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON;
     // for guest, for requests
     if (!AuthProxy::getIdentity() && !$jsonOrApi) {
         // save URL to session and redirect make sense if presentation is null
         Session::set('rollback', Request::getUri()->__toString());
         // add error notice
         Messages::addError($message);
         // redirect to Sign In page
         $url = Router::getUrl('users', 'signin');
         return $this->redirect($url);
     } else {
         return $this->error(new ForbiddenException($message, 403, $exception));
     }
 }
Ejemplo n.º 2
0
 /**
  * Initialize process
  * @param string $environment Array format only!
  * @throws ApplicationException
  * @return void
  */
 public function init($environment = 'production')
 {
     $this->environment = $environment;
     try {
         // initial default helper path
         $this->addHelperPath(dirname(__FILE__) . '/Helper/');
         // first log message
         Logger::info('app:init');
         // setup configuration for current environment
         if ($debug = Config::getData('debug')) {
             $this->debugFlag = (bool) $debug;
         }
         // initial php settings
         if ($ini = Config::getData('php')) {
             foreach ($ini as $key => $value) {
                 $result = ini_set($key, $value);
                 Logger::info('app:init:php:' . $key . ':' . ($result ?: '---'));
             }
         }
         // init session, start inside class
         Session::getInstance();
         // init Messages
         Messages::getInstance();
         // init Translator
         Translator::getInstance();
         // init request
         $this->initRequest();
         // init response
         $this->initResponse();
         // init router
         Router::getInstance();
     } catch (\Exception $e) {
         throw new ApplicationException("Application can't be loaded: " . $e->getMessage());
     }
 }
Ejemplo n.º 3
0
 /**
  * Add message to container
  *
  * @param  string   $type One of error, notice or success
  * @param  string   $message
  * @param  string[] $text
  * @return void
  */
 protected function add($type, $message, ...$text)
 {
     $this->init();
     $this->getMessagesStore()[$type][] = Translator::translate($message, ...$text);
 }
Ejemplo n.º 4
0
 *
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/framework
 */
/**
 * @namespace
 */
namespace Bluz\View\Helper;

use Bluz\View\View;
use Bluz\Proxy\Request;
use Bluz\Proxy\Translator;
return function ($text, $href, array $attributes = []) {
    // if href is settings for url helper
    if (is_array($href)) {
        $href = $this->url(...$href);
    }
    // href can be null, if access is denied
    if (null === $href) {
        return '';
    }
    if ($href == Request::getRequestUri()) {
        if (isset($attributes['class'])) {
            $attributes['class'] .= ' on';
        } else {
            $attributes['class'] = 'on';
        }
    }
    $attributes = $this->attributes($attributes);
    return '<a href="' . $href . '" ' . $attributes . '>' . Translator::translate($text) . '</a>';
};
Ejemplo n.º 5
0
 /**
  * Send email
  * @api
  * @param \PHPMailer $mail
  * @return bool
  * @throws MailerException
  * @todo Add mail to queue
  */
 public function send(\PHPMailer $mail)
 {
     if ($template = $this->getOption('subjectTemplate')) {
         /** @var string $template */
         $mail->Subject = Translator::translate($template, $mail->Subject);
     }
     if (!$mail->Send()) {
         // Why you don't use "Exception mode" of PHPMailer
         // Because we need our Exception in any case
         throw new MailerException('Error mail send: ' . $mail->ErrorInfo);
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Initialize process
  *
  * @param  string $environment
  * @throws ApplicationException
  * @return void
  */
 public function init($environment = 'production')
 {
     $this->environment = $environment;
     try {
         // first log message
         Logger::info('app:init');
         // initial default helper path
         $this->addHelperPath(dirname(__FILE__) . '/Helper/');
         // init Config
         $this->initConfig();
         // init Session, start inside class (if needed)
         Session::getInstance();
         // init Messages
         Messages::getInstance();
         // init Translator
         Translator::getInstance();
         // init Request
         $this->initRequest();
         // init Response
         $this->initResponse();
         // init Router
         $this->initRouter();
     } catch (\Exception $e) {
         throw new ApplicationException("Application can't be loaded: " . $e->getMessage());
     }
 }