Hybrid_Exception: Endpoint: Error while trying to init Hybrid_Auth: You cannot access this page directly.
/home/udiospa/public_html/vendor/hybridauth/hybridauth/hybridauth/Hybrid/Endpoint.php (217)
#0Hybrid_Endpoint->authInit()
/home/udiospa/public_html/vendor/hybridauth/hybridauth/hybridauth/Hybrid/Endpoint.php (117)
<?php
 
/**
 * HybridAuth
 * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
 * (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
 */
 
/**
 * Hybrid_Endpoint class
 *
 * Provides a simple way to handle the OpenID and OAuth endpoint
 */
class Hybrid_Endpoint {
 
  protected $request = null;
  protected $initDone = false;
 
  /**
   * Process the current request
   *
   * @param array $request The current request parameters. Leave as null to default to use $_REQUEST.
   */
  public function __construct($request = null) {
    if (is_null($request)) {
      // Fix a strange behavior when some provider call back ha endpoint
      // with /index.php?hauth.done={provider}?{args}...
      // >here we need to parse $_SERVER[QUERY_STRING]
      $request = $_REQUEST;
      if (isset($_SERVER["QUERY_STRING"]) && strrpos($_SERVER["QUERY_STRING"], '?')) {
        $_SERVER["QUERY_STRING"] = str_replace("?", "&", $_SERVER["QUERY_STRING"]);
        parse_str($_SERVER["QUERY_STRING"], $request);
      }
    }
 
    // Setup request variable
    $this->request = $request;
 
    // If openid_policy requested, we return our policy document
    if (isset($this->request["get"]) && $this->request["get"] == "openid_policy") {
      $this->processOpenidPolicy();
    }
 
    // If openid_xrds requested, we return our XRDS document
    if (isset($this->request["get"]) && $this->request["get"] == "openid_xrds") {
      $this->processOpenidXRDS();
    }
 
    // If we get a hauth.start
    if (isset($this->request["hauth_start"]) && $this->request["hauth_start"]) {
      $this->processAuthStart();
    }
    // Else if hauth.done
    elseif (isset($this->request["hauth_done"]) && $this->request["hauth_done"]) {
      $this->processAuthDone();
    }
    // Else we advertise our XRDS document, something supposed to be done from the Realm URL page
    else {
      $this->processOpenidRealm();
    }
  }
 
  /**
   * Process the current request
   *
   * @param array $request The current request parameters. Leave as null to default to use $_REQUEST.
   * @return Hybrid_Endpoint
   */
  public static function process($request = null) {
    // Trick for PHP 5.2, because it doesn't support late static binding
    $class = function_exists('get_called_class') ? get_called_class() : __CLASS__;
    new $class($request);
  }
 
  /**
   * Process OpenID policy request
   * @return void
   */
  protected function processOpenidPolicy() {
    $output = file_get_contents(dirname(__FILE__) . "/resources/openid_policy.html");
    print $output;
    die();
  }
 
  /**
   * Process OpenID XRDS request
   * @return void
   */
  protected function processOpenidXRDS() {
    header("Content-Type: application/xrds+xml");
 
    $output = str_replace("{RETURN_TO_URL}", str_replace(
            array("<", ">", "\"", "'", "&"), array("&lt;", "&gt;", "&quot;", "&apos;", "&amp;"), Hybrid_Auth::getCurrentUrl(false)
        ), file_get_contents(dirname(__FILE__) . "/resources/openid_xrds.xml"));
    print $output;
    die();
  }
 
  /**
   * Process OpenID realm request
   * @return void
   */
  protected function processOpenidRealm() {
    $output = str_replace("{X_XRDS_LOCATION}", htmlentities(Hybrid_Auth::getCurrentUrl(false), ENT_QUOTES, 'UTF-8')
        . "?get=openid_xrds&v="
        . Hybrid_Auth::$version, file_get_contents(dirname(__FILE__) . "/resources/openid_realm.html"));
    print $output;
    die();
  }
 
  /**
   * Define: endpoint step 3
   * @return void
   * @throws Hybrid_Exception
   */
  protected function processAuthStart() {
    $this->authInit();
 
    $provider_id = trim(strip_tags($this->request["hauth_start"]));
 
    // check if page accessed directly
    if (!Hybrid_Auth::storage()->get("hauth_session.$provider_id.hauth_endpoint")) {
      Hybrid_Logger::error("Endpoint: hauth_endpoint parameter is not defined on hauth_start, halt login process!");
 
      throw new Hybrid_Exception("You cannot access this page directly.");
    }
 
    // define:hybrid.endpoint.php step 2.
    $hauth = Hybrid_Auth::setup($provider_id);
 
    // if REQUESTed hauth_idprovider is wrong, session not created, etc.
    if (!$hauth) {
      Hybrid_Logger::error("Endpoint: Invalid parameter on hauth_start!");
      throw new Hybrid_Exception("Invalid parameter! Please return to the login page and try again.");
    }
 
    try {
      Hybrid_Logger::info("Endpoint: call adapter [{$provider_id}] loginBegin()");
 
      $hauth->adapter->loginBegin();
    } catch (Exception $e) {
      Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
      Hybrid_Error::setError($e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
 
      $hauth->returnToCallbackUrl();
    }
 
    die();
  }
 
  /**
   * Define: endpoint step 3.1 and 3.2
   * @return void
   * @throws Hybrid_Exception
   */
  protected function processAuthDone() {
    $this->authInit();
 
    $provider_id = trim(strip_tags($this->request["hauth_done"]));
 
    $hauth = Hybrid_Auth::setup($provider_id);
 
    if (!$hauth) {
      Hybrid_Logger::error("Endpoint: Invalid parameter on hauth_done!");
 
      $hauth->adapter->setUserUnconnected();
 
      throw new Hybrid_Exception("Invalid parameter! Please return to the login page and try again.");
    }
 
    try {
      Hybrid_Logger::info("Endpoint: call adapter [{$provider_id}] loginFinish() ");
      $hauth->adapter->loginFinish();
    } catch (Exception $e) {
      Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
      Hybrid_Error::setError($e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
 
      $hauth->adapter->setUserUnconnected();
    }
 
    Hybrid_Logger::info("Endpoint: job done. return to callback url.");
 
    $hauth->returnToCallbackUrl();
    die();
  }
 
  /**
   * Initializes authentication
   * @throws Hybrid_Exception
   */
  protected function authInit() {
    if (!$this->initDone) {
      $this->initDone = true;
 
      // Init Hybrid_Auth
      try {
        if (!class_exists("Hybrid_Storage", false)) {
          require_once realpath(dirname(__FILE__)) . "/Storage.php";
        }
        if (!class_exists("Hybrid_Exception", false)) {
          require_once realpath(dirname(__FILE__)) . "/Exception.php";
        }
        if (!class_exists("Hybrid_Logger", false)) {
          require_once realpath(dirname(__FILE__)) . "/Logger.php";
        }
 
        $storage = new Hybrid_Storage();
 
        // Check if Hybrid_Auth session already exist
        if (!$storage->config("CONFIG")) {
          throw new Hybrid_Exception("You cannot access this page directly.");
        }
 
        Hybrid_Auth::initialize($storage->config("CONFIG"));
      } catch (Exception $e) {
        Hybrid_Logger::error("Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage());
        throw new Hybrid_Exception( "Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage(), $e->getCode(), $e );
      }
    }
  }
 
#1Hybrid_Endpoint->processAuthStart()
/home/udiospa/public_html/vendor/hybridauth/hybridauth/hybridauth/Hybrid/Endpoint.php (51)
<?php
 
/**
 * HybridAuth
 * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
 * (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
 */
 
/**
 * Hybrid_Endpoint class
 *
 * Provides a simple way to handle the OpenID and OAuth endpoint
 */
class Hybrid_Endpoint {
 
  protected $request = null;
  protected $initDone = false;
 
  /**
   * Process the current request
   *
   * @param array $request The current request parameters. Leave as null to default to use $_REQUEST.
   */
  public function __construct($request = null) {
    if (is_null($request)) {
      // Fix a strange behavior when some provider call back ha endpoint
      // with /index.php?hauth.done={provider}?{args}...
      // >here we need to parse $_SERVER[QUERY_STRING]
      $request = $_REQUEST;
      if (isset($_SERVER["QUERY_STRING"]) && strrpos($_SERVER["QUERY_STRING"], '?')) {
        $_SERVER["QUERY_STRING"] = str_replace("?", "&", $_SERVER["QUERY_STRING"]);
        parse_str($_SERVER["QUERY_STRING"], $request);
      }
    }
 
    // Setup request variable
    $this->request = $request;
 
    // If openid_policy requested, we return our policy document
    if (isset($this->request["get"]) && $this->request["get"] == "openid_policy") {
      $this->processOpenidPolicy();
    }
 
    // If openid_xrds requested, we return our XRDS document
    if (isset($this->request["get"]) && $this->request["get"] == "openid_xrds") {
      $this->processOpenidXRDS();
    }
 
    // If we get a hauth.start
    if (isset($this->request["hauth_start"]) && $this->request["hauth_start"]) {
      $this->processAuthStart();
    }
    // Else if hauth.done
    elseif (isset($this->request["hauth_done"]) && $this->request["hauth_done"]) {
      $this->processAuthDone();
    }
    // Else we advertise our XRDS document, something supposed to be done from the Realm URL page
    else {
      $this->processOpenidRealm();
    }
  }
 
  /**
   * Process the current request
   *
   * @param array $request The current request parameters. Leave as null to default to use $_REQUEST.
   * @return Hybrid_Endpoint
   */
  public static function process($request = null) {
    // Trick for PHP 5.2, because it doesn't support late static binding
    $class = function_exists('get_called_class') ? get_called_class() : __CLASS__;
    new $class($request);
  }
 
  /**
   * Process OpenID policy request
   * @return void
   */
  protected function processOpenidPolicy() {
    $output = file_get_contents(dirname(__FILE__) . "/resources/openid_policy.html");
    print $output;
    die();
  }
 
  /**
   * Process OpenID XRDS request
   * @return void
   */
  protected function processOpenidXRDS() {
    header("Content-Type: application/xrds+xml");
 
    $output = str_replace("{RETURN_TO_URL}", str_replace(
            array("<", ">", "\"", "'", "&"), array("&lt;", "&gt;", "&quot;", "&apos;", "&amp;"), Hybrid_Auth::getCurrentUrl(false)
        ), file_get_contents(dirname(__FILE__) . "/resources/openid_xrds.xml"));
    print $output;
    die();
  }
 
  /**
   * Process OpenID realm request
   * @return void
   */
  protected function processOpenidRealm() {
    $output = str_replace("{X_XRDS_LOCATION}", htmlentities(Hybrid_Auth::getCurrentUrl(false), ENT_QUOTES, 'UTF-8')
        . "?get=openid_xrds&v="
        . Hybrid_Auth::$version, file_get_contents(dirname(__FILE__) . "/resources/openid_realm.html"));
    print $output;
    die();
  }
 
  /**
   * Define: endpoint step 3
   * @return void
   * @throws Hybrid_Exception
   */
  protected function processAuthStart() {
    $this->authInit();
 
    $provider_id = trim(strip_tags($this->request["hauth_start"]));
 
    // check if page accessed directly
    if (!Hybrid_Auth::storage()->get("hauth_session.$provider_id.hauth_endpoint")) {
      Hybrid_Logger::error("Endpoint: hauth_endpoint parameter is not defined on hauth_start, halt login process!");
 
      throw new Hybrid_Exception("You cannot access this page directly.");
    }
 
    // define:hybrid.endpoint.php step 2.
    $hauth = Hybrid_Auth::setup($provider_id);
 
    // if REQUESTed hauth_idprovider is wrong, session not created, etc.
    if (!$hauth) {
      Hybrid_Logger::error("Endpoint: Invalid parameter on hauth_start!");
      throw new Hybrid_Exception("Invalid parameter! Please return to the login page and try again.");
    }
 
    try {
      Hybrid_Logger::info("Endpoint: call adapter [{$provider_id}] loginBegin()");
 
      $hauth->adapter->loginBegin();
    } catch (Exception $e) {
      Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
      Hybrid_Error::setError($e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
 
      $hauth->returnToCallbackUrl();
    }
 
    die();
  }
 
  /**
   * Define: endpoint step 3.1 and 3.2
   * @return void
   * @throws Hybrid_Exception
   */
  protected function processAuthDone() {
    $this->authInit();
 
    $provider_id = trim(strip_tags($this->request["hauth_done"]));
 
    $hauth = Hybrid_Auth::setup($provider_id);
 
    if (!$hauth) {
      Hybrid_Logger::error("Endpoint: Invalid parameter on hauth_done!");
 
      $hauth->adapter->setUserUnconnected();
 
      throw new Hybrid_Exception("Invalid parameter! Please return to the login page and try again.");
    }
 
    try {
      Hybrid_Logger::info("Endpoint: call adapter [{$provider_id}] loginFinish() ");
      $hauth->adapter->loginFinish();
    } catch (Exception $e) {
      Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
      Hybrid_Error::setError($e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
 
      $hauth->adapter->setUserUnconnected();
    }
 
    Hybrid_Logger::info("Endpoint: job done. return to callback url.");
 
    $hauth->returnToCallbackUrl();
    die();
  }
 
  /**
   * Initializes authentication
   * @throws Hybrid_Exception
   */
  protected function authInit() {
    if (!$this->initDone) {
      $this->initDone = true;
 
      // Init Hybrid_Auth
      try {
        if (!class_exists("Hybrid_Storage", false)) {
          require_once realpath(dirname(__FILE__)) . "/Storage.php";
        }
        if (!class_exists("Hybrid_Exception", false)) {
          require_once realpath(dirname(__FILE__)) . "/Exception.php";
        }
        if (!class_exists("Hybrid_Logger", false)) {
          require_once realpath(dirname(__FILE__)) . "/Logger.php";
        }
 
        $storage = new Hybrid_Storage();
 
        // Check if Hybrid_Auth session already exist
        if (!$storage->config("CONFIG")) {
          throw new Hybrid_Exception("You cannot access this page directly.");
        }
 
        Hybrid_Auth::initialize($storage->config("CONFIG"));
      } catch (Exception $e) {
        Hybrid_Logger::error("Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage());
        throw new Hybrid_Exception( "Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage(), $e->getCode(), $e );
      }
    }
  }
 
#2Hybrid_Endpoint->__construct(null)
/home/udiospa/public_html/vendor/hybridauth/hybridauth/hybridauth/Hybrid/Endpoint.php (72)
<?php
 
/**
 * HybridAuth
 * http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
 * (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
 */
 
/**
 * Hybrid_Endpoint class
 *
 * Provides a simple way to handle the OpenID and OAuth endpoint
 */
class Hybrid_Endpoint {
 
  protected $request = null;
  protected $initDone = false;
 
  /**
   * Process the current request
   *
   * @param array $request The current request parameters. Leave as null to default to use $_REQUEST.
   */
  public function __construct($request = null) {
    if (is_null($request)) {
      // Fix a strange behavior when some provider call back ha endpoint
      // with /index.php?hauth.done={provider}?{args}...
      // >here we need to parse $_SERVER[QUERY_STRING]
      $request = $_REQUEST;
      if (isset($_SERVER["QUERY_STRING"]) && strrpos($_SERVER["QUERY_STRING"], '?')) {
        $_SERVER["QUERY_STRING"] = str_replace("?", "&", $_SERVER["QUERY_STRING"]);
        parse_str($_SERVER["QUERY_STRING"], $request);
      }
    }
 
    // Setup request variable
    $this->request = $request;
 
    // If openid_policy requested, we return our policy document
    if (isset($this->request["get"]) && $this->request["get"] == "openid_policy") {
      $this->processOpenidPolicy();
    }
 
    // If openid_xrds requested, we return our XRDS document
    if (isset($this->request["get"]) && $this->request["get"] == "openid_xrds") {
      $this->processOpenidXRDS();
    }
 
    // If we get a hauth.start
    if (isset($this->request["hauth_start"]) && $this->request["hauth_start"]) {
      $this->processAuthStart();
    }
    // Else if hauth.done
    elseif (isset($this->request["hauth_done"]) && $this->request["hauth_done"]) {
      $this->processAuthDone();
    }
    // Else we advertise our XRDS document, something supposed to be done from the Realm URL page
    else {
      $this->processOpenidRealm();
    }
  }
 
  /**
   * Process the current request
   *
   * @param array $request The current request parameters. Leave as null to default to use $_REQUEST.
   * @return Hybrid_Endpoint
   */
  public static function process($request = null) {
    // Trick for PHP 5.2, because it doesn't support late static binding
    $class = function_exists('get_called_class') ? get_called_class() : __CLASS__;
    new $class($request);
  }
 
  /**
   * Process OpenID policy request
   * @return void
   */
  protected function processOpenidPolicy() {
    $output = file_get_contents(dirname(__FILE__) . "/resources/openid_policy.html");
    print $output;
    die();
  }
 
  /**
   * Process OpenID XRDS request
   * @return void
   */
  protected function processOpenidXRDS() {
    header("Content-Type: application/xrds+xml");
 
    $output = str_replace("{RETURN_TO_URL}", str_replace(
            array("<", ">", "\"", "'", "&"), array("&lt;", "&gt;", "&quot;", "&apos;", "&amp;"), Hybrid_Auth::getCurrentUrl(false)
        ), file_get_contents(dirname(__FILE__) . "/resources/openid_xrds.xml"));
    print $output;
    die();
  }
 
  /**
   * Process OpenID realm request
   * @return void
   */
  protected function processOpenidRealm() {
    $output = str_replace("{X_XRDS_LOCATION}", htmlentities(Hybrid_Auth::getCurrentUrl(false), ENT_QUOTES, 'UTF-8')
        . "?get=openid_xrds&v="
        . Hybrid_Auth::$version, file_get_contents(dirname(__FILE__) . "/resources/openid_realm.html"));
    print $output;
    die();
  }
 
  /**
   * Define: endpoint step 3
   * @return void
   * @throws Hybrid_Exception
   */
  protected function processAuthStart() {
    $this->authInit();
 
    $provider_id = trim(strip_tags($this->request["hauth_start"]));
 
    // check if page accessed directly
    if (!Hybrid_Auth::storage()->get("hauth_session.$provider_id.hauth_endpoint")) {
      Hybrid_Logger::error("Endpoint: hauth_endpoint parameter is not defined on hauth_start, halt login process!");
 
      throw new Hybrid_Exception("You cannot access this page directly.");
    }
 
    // define:hybrid.endpoint.php step 2.
    $hauth = Hybrid_Auth::setup($provider_id);
 
    // if REQUESTed hauth_idprovider is wrong, session not created, etc.
    if (!$hauth) {
      Hybrid_Logger::error("Endpoint: Invalid parameter on hauth_start!");
      throw new Hybrid_Exception("Invalid parameter! Please return to the login page and try again.");
    }
 
    try {
      Hybrid_Logger::info("Endpoint: call adapter [{$provider_id}] loginBegin()");
 
      $hauth->adapter->loginBegin();
    } catch (Exception $e) {
      Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
      Hybrid_Error::setError($e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
 
      $hauth->returnToCallbackUrl();
    }
 
    die();
  }
 
  /**
   * Define: endpoint step 3.1 and 3.2
   * @return void
   * @throws Hybrid_Exception
   */
  protected function processAuthDone() {
    $this->authInit();
 
    $provider_id = trim(strip_tags($this->request["hauth_done"]));
 
    $hauth = Hybrid_Auth::setup($provider_id);
 
    if (!$hauth) {
      Hybrid_Logger::error("Endpoint: Invalid parameter on hauth_done!");
 
      $hauth->adapter->setUserUnconnected();
 
      throw new Hybrid_Exception("Invalid parameter! Please return to the login page and try again.");
    }
 
    try {
      Hybrid_Logger::info("Endpoint: call adapter [{$provider_id}] loginFinish() ");
      $hauth->adapter->loginFinish();
    } catch (Exception $e) {
      Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
      Hybrid_Error::setError($e->getMessage(), $e->getCode(), $e->getTraceAsString(), $e->getPrevious());
 
      $hauth->adapter->setUserUnconnected();
    }
 
    Hybrid_Logger::info("Endpoint: job done. return to callback url.");
 
    $hauth->returnToCallbackUrl();
    die();
  }
 
  /**
   * Initializes authentication
   * @throws Hybrid_Exception
   */
  protected function authInit() {
    if (!$this->initDone) {
      $this->initDone = true;
 
      // Init Hybrid_Auth
      try {
        if (!class_exists("Hybrid_Storage", false)) {
          require_once realpath(dirname(__FILE__)) . "/Storage.php";
        }
        if (!class_exists("Hybrid_Exception", false)) {
          require_once realpath(dirname(__FILE__)) . "/Exception.php";
        }
        if (!class_exists("Hybrid_Logger", false)) {
          require_once realpath(dirname(__FILE__)) . "/Logger.php";
        }
 
        $storage = new Hybrid_Storage();
 
        // Check if Hybrid_Auth session already exist
        if (!$storage->config("CONFIG")) {
          throw new Hybrid_Exception("You cannot access this page directly.");
        }
 
        Hybrid_Auth::initialize($storage->config("CONFIG"));
      } catch (Exception $e) {
        Hybrid_Logger::error("Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage());
        throw new Hybrid_Exception( "Endpoint: Error while trying to init Hybrid_Auth: " . $e->getMessage(), $e->getCode(), $e );
      }
    }
  }
 
#3Hybrid_Endpoint::process()
/home/udiospa/public_html/application/modules/frontend/controllers/AuthController.php (552)
<?php
 
namespace Frontend\Controller;
 
use Frontend\Form\ResetPasswordEnterForm;
use Frontend\Form\ResetPasswordForm;
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\View;
use Projects\Model\ProjectInviteEmail;
use Projects\Model\ProjectPrivateUser;
use User\Model\Group;
use User\Model\Invite;
use User\Model\MailDelivery;
use User\Model\MailTemplate;
use User\Model\OauthUsers;
use User\Model\PasswordRecovery;
use User\Model\SuccessLogins;
use Phalcon\Validation;
use Phalcon\Validation\Message;
use Phalcon\Validation\Validator;
use Phalcon\Validation\ValidatorInterface;
use User\Model\User;
 
use Exception;
use Phalcon\Mvc\Dispatcher as PhalconDispatcher;
 
/**
 * Created by Novnik Ltd.
 * User: AtrDevue - AuthController.php
 * Date: 21.09.16
 * Time: 16:56
 * Project: ubiospace
 *
 * Class AuthController
 *
 * @package Frontend\Controller
 */
class AuthController extends BaseController
{
    /**
     * @var bool
     */
    public $public_auth = false;
 
    /**
     * @var bool
     */
    public $project_auth = false;
 
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
 
        // If this user is authorized, then redirect it to the home page
        if ($this->user)
        {
            return $this->response->redirect('/', true)->send();
        }
    }
 
    /**
     * Login action
     */
    public function loginAction()
    {
 
        $form = new \Frontend\Form\LoginForm();
 
        if ($this->session->has('auth-identity'))
        {
            $this->session->destroy();
            return $this->response->redirect('/login', true)->send();
        }
 
        $referal_page = substr(strrchr($this->request->getHTTPReferer(), $this->config->host), 20);
        if ($referal_page && $referal_page != '/login')
        {
            // Redirect to the referal page
            $this->persistent->refere = $referal_page;
        }
 
        if ($this->request->isPost())
        {
            try
            {
                // Сheck Token
                if ($this->security->checkToken())
                {
                    if ($form->isValid($this->request->getPost()))
                    {
 
                        $auth = $this->auth->check($this->request->getPost('email', ['trim', 'email']),
                            $this->request->getPost('password', ['trim', 'string']),
                            $this->config->access->get('frontend')->toArray(),
                            // User groups that are allowed access
                            $this->request->getPost('remember', null, false), 1);
 
                        // Check user authentication system
                        if ($auth === true)
                        {
                            $redirect = $this->request->get('redir', 'string', $this->persistent->refere);
 
                            if (!empty($redirect))
                            {
                                $this->persistent->refere = false;
                                // Redirect to the main page
                                return $this->response->redirect($redirect);
                            }
 
 
                            // Redirect to the main page
                            return $this->response->redirect('user/dashboard');
                        }
 
                        $this->flashSession->error($this->mes->_("auth.authorisation_error") . ' ' . $this->mes->_("auth.check_input_email_password"));
                    }
                } else
                {
                    $this->flashSession->error($this->mes->_("main.csrf_failed"));
                }
            } catch (\Phalcon\Exception $e)
            {
                //@@TODO output flash error
                if (APPLICATION_ENV == 'development')
                {
                    $this->flashSession->error($e->getMessage());
                } else
                {
                    $this->flashSession->error($this->mes->_("auth.authorisation_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
                }
 
            }
        }
 
        $this->view->form = $form;
    }
 
    /**
     * Reset Password
     */
    public function resetAction()
    {
        //$this->auth->authUserById(39);
        $form = new ResetPasswordForm();
 
        if ($this->request->isPost())
        {
            try
            {
                // Сheck Token
                if (!$this->security->checkToken())
                {
                    $this->flashSession->error($this->mes->_("main.csrf_failed"));
                    goto break_free_of_try;
                }
 
                if ($form->isValid($this->request->getPost()))
                {
                    $email = $this->request->getPost('email');
 
                    $user = User::findFirst([
                        "conditions" => "email = :email: AND active = '1'",
                        "bind"       => compact('email')
                    ]);
 
                    if (!$user)
                    {
                        $this->flashSession->error($this->mes->_("auth.no_such_user_database"));
                        goto break_free_of_try;
                    }
 
                    /*
                     * If the user is found with such email, then send a letter.
                     * If not, we will not report it to the user. To reduce the chance of selection of email
                     */
                    if (!$password_reset = PasswordRecovery::findFirst([
                        "conditions" => "user_id = ?1",
                        "bind"       => [1 => $user->user_id]
                    ])
                    )
                    {
                        $password_reset          = new PasswordRecovery();
                        $password_reset->user_id = $user->user_id;
                    }
 
                    $hash                 = $this->crypt->encryptBase64($user->email, $this->crypt->getKey(), true);
                    $password_reset->hash = $hash;
 
                    if ($password_reset->save())
                    {
                        // Get template for Email
                        $template_email = MailTemplate::findFirst(1);
 
                        $html = $this->helpers->parseHtml($template_email->body, [
                            'url'        => $this->config['host'] . $this->url->get('admin'),
                            'link'       => $this->config['host'] . $this->url->get('password_recovery/' . $hash),
                            'first_name' => $user->first_name
                        ]);
 
                        // add to queue
                        $mail_delivery           = new MailDelivery();
                        $mail_delivery->receiver = $email;
                        $mail_delivery->html     = $html;
                        $mail_delivery->subject  = $template_email->subject;
                        $mail_delivery->save();
 
                        $this->flashSession->success($this->mes->_("auth.your_mailbox_sent_reset_your_password"));
                        goto break_free_of_try;
 
                    }
 
                    $this->flashSession->error($this->mes->_("auth.reset_password_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
                }
 
            } catch (\Phalcon\Exception $e)
            {
                $this->flashSession->error($e->getMessage());
            }
        }
 
        break_free_of_try:
 
        $this->view->form = $form;
    }
 
    /**
     * Reset Password
     *
     * @param $code
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     */
    public function reset_emailAction($code)
    {
        $time = time() - 36 * 24 * 3600;
 
        $rp = PasswordRecovery::findFirst([
            "conditions" => "hash = :code: AND create_at > :time:",
            "bind"       => compact('code', 'time')
        ]);
 
        if (!$rp)
        {
            $this->flashSession->error($this->mes->_("auth.wrong_code_outdated_link"));
 
            return $this->response->redirect('reset-password');
        }
 
        $user = User::findFirst($rp->user_id);
 
        if (!$user)
        {
            $this->flashSession->error($this->mes->_("auth.user_owns_code_blocked_deleted"));
 
            return $this->response->redirect('reset-password');
        }
 
        $form = new ResetPasswordEnterForm();
 
        if ($this->request->isPost())
        {
            try
            {
 
                // Сheck Token
                if (!$this->security->checkToken())
                {
                    $this->flashSession->error($this->mes->_("main.csrf_failed"));
                    goto break_free_of_try;
                }
 
                if ($form->isValid($this->request->getPost()))
                {
                    $password = $this->getDI()->getSecurity()->hash($this->request->getPost('password'));
 
                    if ($user->update(compact('password')))
                    {
                        // Delete recovery password
                        $rp->delete();
 
                        $this->flashSession->success($this->mes->_("auth.you_successfully_changed_password_sign_password"));
 
                        return $this->response->redirect('login');
                    }
 
                    $this->flashSession->error($this->mes->_("auth.when_recovering_password_error_occurred") . ' ' . $this->mes->_("main.please_contact_administrator"));
 
                }
            } catch (\Phalcon\Exception $e)
            {
                $this->flashSession->error($e->getMessage());
            }
        }
 
        break_free_of_try:
 
        $this->view->form = $form;
    }
 
    /**
     * @param null $code
     */
    public function registerAction($code = null)
    {
        $data                   = $this->settings['registration'];
        $data['project_invite'] = $this->request->get('project_invite', 'string', null);
 
        $project_invite = false;
 
        if (!empty($data['project_invite']))
        {
            $project_invite = ProjectInviteEmail::findFirst([
                "conditions" => "code = :code: AND status = '0'",
                "bind"       => ['code' => $data['project_invite']]
            ]);
        }
 
        $error = false;
 
        // If is this the artist does not need then invite
        if ($this->request->isPost())
        {
            $group_id = $this->request->getPost('group_id', 'int');
 
            if ($group_id == 1)
            {
                $data                   = ['invite' => 0];
                $data['project_invite'] = $this->request->get('project_invite', 'string', null);
            }
 
            // social login. Check request form
            $provider = $this->request->getPost('auth', 'string', null);
 
            if (is_null($provider))
            {
                $data['username']   = 1;
                $data['password']   = 1;
                $data['email']      = 1;
                $data['first_name'] = 1;
                $data['last_name']  = 1;
                $data['agree']      = 1;
            } else
            {
                $this->public_auth = true;
            }
        }
 
        $user = new User();
        if (!is_null($code))
        {
            $user->invite   = $code;
            $user->group_id = 2;
        }
 
        if (!empty($project_invite))
        {
            $user->email = $project_invite->email;
        }
 
        $form = new \Frontend\Form\RegisterForm($user, $data);
 
        if ($this->request->isPost())
        {
            try
            {
                // Сheck Token
                if ($this->security->checkToken())
                {
                    if ($form->isValid($this->request->getPost()))
                    {
                        $invite = $this->request->getPost('invite', 'string', null);
 
                        // if social auth
                        if ($this->public_auth)
                        {
                            $post_form                = $this->request->getPost();
                            $post_form['need_invite'] = $data['invite'];
 
                            $this->session->set("public_auth", $post_form);
 
                            return $this->response->redirect('hybridauth/' . $provider);
                        }
 
                        // Сheck for duplicate username
                        if ($username = $this->request->getPost('username', 'string'))
                        {
                            $valid_username = User::findFirst([
                                "conditions" => "username = ?1",
                                "bind"       => [1 => $username]
                            ]);
 
                            if ($valid_username)
                            {
                                $error    = true;
                                $messages = $form->getMessagesFor('username');
                                $messages->appendMessage(new Message($this->mes->_("auth.this_username_already_exists")));
                            }
                        }
 
                        // Сheck for duplicate email
                        if ($email = $this->request->getPost('email', 'string'))
                        {
                            $valid_email = User::findFirst([
                                "conditions" => "email = ?1",
                                "bind"       => [1 => $email]
                            ]);
 
                            if ($valid_email)
                            {
                                $error    = true;
                                $messages = $form->getMessagesFor('email');
                                $messages->appendMessage(new Message($this->mes->_("auth.this_email_already_exists")));
                            }
                        }
 
                        $get_database_invite = null;
 
                        // Check, invite
                        if ($data['invite'] == 1)
                        {
                            $messages = $form->getMessagesFor('invite');
 
                            // Get data base
                            $get_database_invite = Invite::findFirst([
                                "conditions" => "link = ?1",
                                "bind"       => [1 => $invite]
                            ]);
 
                            if (!$get_database_invite)
                            {
                                $error = true;
                                $messages->appendMessage(new Message($this->mes->_("auth.in_database_not_found_invite")));
                            } else
                            {
                                // Checking for use
                                if ($get_database_invite->used == 1)
                                {
                                    $error = true;
                                    $messages->appendMessage(new Message($this->mes->_("auth.this_invite_has_already_been_used")));
                                }
 
                                // Check at the email
                                if ($get_database_invite->email != $this->request->getPost('email', 'email', null))
                                {
                                    $error = true;
                                    $messages->appendMessage(new Message($this->mes->_("auth.your_email_address_does_not_match")));
                                }
 
                                // Check at the time of use
                                if ($get_database_invite->create_date <= time() - 14 * 24 * 3600)
                                {
                                    $error = true;
                                    $messages->appendMessage(new Message($this->mes->_("auth.overdue_time_invite_use_this")));
                                }
                            }
 
                        }
 
                        if (!$error)
                        {
                            if ($user->save())
                            {
                                if ($data['invite'] == 1 && !empty($get_database_invite))
                                {
                                    // Update invite. Put the value - used
                                    $get_database_invite->update(['used' => 1]);
 
                                }
 
                                // If project invite
                                if (!empty($data['project_invite']) && !empty($project_invite))
                                {
                                    $project_invite->update(['status' => 1, 'user_id' => $user->user_id]);
 
                                    // New item for Private Project
                                    $project_private_user             = new ProjectPrivateUser();
                                    $project_private_user->user_id    = $user->user_id;
                                    $project_private_user->project_id = $project_invite->project_id;
                                    $project_private_user->save();
                                }
 
                                // Auth user
                                $this->auth->authUserById($user->user_id);
 
                                $this->flashSession->success($this->mes->_("auth.successfully_signed_system"));
 
                                // Redirect to the profile page
                                return $this->response->redirect('user/dashboard/edit_profile');
                            } else
                            {
                                //@@TODO output flash error
                                if (APPLICATION_ENV == 'development')
                                {
                                    $messages = $user->getMessages();
 
                                    $out_mes = '';
 
                                    foreach ($messages as $message)
                                    {
                                        $out_mes = $message . "\n";
                                    }
                                    $this->flashSession->error($out_mes);
                                } else
                                {
                                    $this->flashSession->error($this->mes->_("auth.registration_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
                                }
                            }
                        } else
                        {
                            $this->flashSession->error($this->mes->_("auth.error_occurred_while_registering"));
                        }
 
                    }
                } else
                {
                    $this->flashSession->error($this->mes->_("main.csrf_failed"));
                }
            } catch (\Phalcon\Exception $e)
            {
                //@@TODO output flash error
                if (APPLICATION_ENV == 'development')
                {
                    $this->flashSession->error($e->getMessage());
                } else
                {
                    $this->flashSession->error($this->mes->_("auth.registration_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
                }
 
            }
        }
 
        $this->view->setVars([
            'form'           => $form,
            'invite'         => $this->settings['registration']['invite'],
            'project_invite' => $project_invite,
            'data'           => $data
        ]);
    }
 
 
    /**
     * @param $provider
     *
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     */
    public function hybridauthAction($provider)
    {
        $provider = substr($provider, 1);
 
        if ($provider == 'socialauth')
        {
            \Hybrid_Endpoint::process();
        }
 
        $return_login    = 'login';
        $return_register = 'register';
        $return_profile  = 'user/dashboard/edit_profile';
        $return_home     = 'user/dashboard';
 
        try
        {
            switch ($provider)
            {
                case 'facebook':
                    $adapter = $this->hybridauth->authenticate("Facebook");
                    break;
                case 'google':
                    $adapter = $this->hybridauth->authenticate("Google");
                    break;
                case 'twitter':
                    $adapter = $this->hybridauth->authenticate("Twitter");
                    break;
                case 'github':
                    $adapter = $this->hybridauth->authenticate("GitHub");
                    break;
            }
 
            if (!empty($adapter))
            {
                // request user profile
                $user_profile = $adapter->getUserProfile();
 
                // if register
                if ($this->session->has("public_auth"))
                {
                    $this->public_auth = $this->session->get("public_auth");
                    $this->session->remove("public_auth");
                }
 
                // Check user on the basis of
                $user = OauthUsers::findFirst([
                    'conditions' => 'identifier = :identifier: AND provider = :provider:',
                    'bind'       => [
                        'identifier' => $user_profile->identifier,
                        'provider'   => $provider,
                    ]
                ]);
 
                // log out provider
                $adapter->logout();
 
                // if the has user
                if ($user)
                {
                    // if this registration and isset user
                    if ($this->public_auth)
                    {
                        $this->flashSession->error($this->mes->_("auth.you_already_registered"));
 
                        return $this->response->redirect($return_register);
                    }
 
                    // Auth user
                    $this->auth->authUserById($user->user_id);
 
                    return $this->response->redirect($return_home);
                } else
                {
                    if ($this->public_auth)
                    {
                        $error = false;
                        // Check, invite
                        if (!empty($this->public_auth['need_invite']) && !empty($this->public_auth['invite']))
                        {
                            $invite = $this->public_auth['invite'];
                            // Get data base
                            $get_database_invite = Invite::findFirst([
                                "conditions" => "link = ?1",
                                "bind"       => [1 => $invite]
                            ]);
 
                            if (!$get_database_invite)
                            {
                                $error = true;
                                $this->flashSession->error($this->mes->_("auth.in_database_not_found_invite"));
                            } else
                            {
                                // Checking for use
                                if ($get_database_invite->used == 1)
                                {
                                    $error = true;
                                    $this->flashSession->error($this->mes->_("auth.this_invite_has_already_been_used"));
                                }
 
                                // Check at the email
                                if ($get_database_invite->email != $user_profile->email)
                                {
                                    $error = true;
                                    $this->flashSession->error($this->mes->_("auth.your_email_address_does_not_match"));
                                }
 
                                // Check at the time of use
                                if ($get_database_invite->create_date <= time() - 14 * 24 * 3600)
                                {
                                    $error = true;
                                    $this->flashSession->error($this->mes->_("auth.overdue_time_invite_use_this"));
                                }
                            }
 
                        }
 
                        if ($error != false)
                        {
                            return $this->response->redirect($return_register);
                        }
 
                        // register user
                        $new_user        = new User();
                        $new_user->email =
                            !empty($user_profile->email) ? $user_profile->email : $this->public_auth['email'];
 
                        // dublicate email
                        $dublicate_email = User::count([
                            'conditions' => 'email = :email:',
                            'bind'       => ['email' => $new_user->email]
                        ]);
 
                        if ($dublicate_email > 0)
                        {
                            $this->flashSession->error($this->mes->_("auth.user_with_email_address_already_exists"));
 
                            return $this->response->redirect($return_register);
                        }
 
                        if (!empty($user_profile->username))
                        {
                            $username = $user_profile->username;
                        } else
                        {
                            $username = $this->helpers->alias($user_profile->displayName);
                        }
 
                        // dublicate username
                        $dublicate_username = User::count([
                            'conditions' => 'username = :username:',
                            'bind'       => ['username' => $username]
                        ]);
 
                        if ($dublicate_username > 0)
                        {
                            $this->flashSession->error($this->mes->_("auth.user_with_this_username_already_exists"));
 
                            return $this->response->redirect($return_register);
                        }
 
                        $new_user->username   = !empty($username) ? $username : $this->public_auth['username'];
                        $new_user->first_name =
                            !empty($user_profile->firstName) ? $user_profile->firstName : $this->public_auth['first_name'];
                        $new_user->last_name  = !empty($user_profile->lastName) ? $user_profile->lastName : ' ';
                        $new_user->city       = $user_profile->city;
                        $new_user->biography  = $user_profile->description;
                        $new_user->password   = $this->helpers->generate_code_i();
                        $new_user->group_id   = (int)$this->public_auth['group_id'];
 
                        if ($new_user->save())
                        {
                            if (!empty($this->public_auth['need_invite']) && !empty($this->public_auth['invite']))
                            {
                                // Update invite. Put the value - used
                                $get_database_invite->update(['used' => 1]);
 
                            }
 
                            // add social user link
                            $oauth_user             = new OauthUsers();
                            $oauth_user->user_id    = $new_user->user_id;
                            $oauth_user->identifier = $user_profile->identifier;
                            $oauth_user->provider   = $provider;
                            $oauth_user->save();
 
                            // Auth user
                            $this->auth->authUserById($new_user->user_id);
 
                            $this->flashSession->success($this->mes->_("auth.successfully_signed_system"));
 
                            // Redirect to the profile page
                            return $this->response->redirect($return_profile);
                        } else
                        {
                            //@@TODO output flash error
                            if (APPLICATION_ENV == 'development')
                            {
                                $messages = $new_user->getMessages();
 
                                $out_mes = '';
 
                                foreach ($messages as $message)
                                {
                                    $out_mes = $message . "\n";
                                }
                                $this->flashSession->error($out_mes);
                            } else
                            {
                                $this->flashSession->error($this->mes->_("auth.registration_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
                            }
                        }
 
                        return $this->response->redirect($return_register);
                    }
 
                    $this->flashSession->error($this->mes->_("auth.no_such_user_system_register_other_provider"));
 
                    return $this->response->redirect($return_login);
                }
            }
        } catch (\Exception $e)
        {
            $this->logger->error('1) ' . $e->getMessage());
            $this->flashSession->error($this->mes->_("auth.isp_connection_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
 
            return $this->response->redirect($return_login);
        }
    }
 
    /**
     * @param $provider
     *
     * @return bool
     */
    public function authprojectAction($provider)
    {
        $config_hybridauth             = $this->config->hybridauth->toArray();
        $config_hybridauth['base_url'] = str_replace("hybridauth", "authproject", $config_hybridauth['base_url']);
 
        $hybridauth = new \Hybrid_Auth($config_hybridauth);
 
        $provider = substr($provider, 1);
 
        if ($provider == 'socialauth')
        {
            \Hybrid_Endpoint::process();
        }
 
        try
        {
 
            switch ($provider)
            {
                case 'facebook':
                    $adapter = $hybridauth->authenticate("Facebook");
                    break;
                case 'google':
                    $adapter = $hybridauth->authenticate("Google");
                    break;
                case 'twitter':
                    $adapter = $hybridauth->authenticate("Twitter");
                    break;
                case 'github':
                    $adapter = $hybridauth->authenticate("GitHub");
                    break;
            }
 
            if (!empty($adapter))
            {
                // request user profile
                $user_profile = $adapter->getUserProfile();
                // log out provider
                $adapter->logout();
 
                // Check user on the basis of
                $user = OauthUsers::findFirst([
                    'conditions' => 'identifier = :identifier: AND provider = :provider:',
                    'bind'       => [
                        'identifier' => $user_profile->identifier,
                        'provider'   => $provider,
                    ]
                ]);
 
                // if register
                if ($this->session->has("project_auth"))
                {
                    $this->project_auth = $this->session->get("project_auth");
                    $this->session->remove("project_auth");
                }
 
                // if the has user
                if ($user)
                {
                    // Auth user
                    $this->auth->authUserById($user->user_id);
 
                    $this->flashSession->success($this->mes->_("auth.successfully_signed_system"));
 
                    return $this->response->redirect('post/project');
                }
 
                // else register user as Artist
                $new_user        = new User();
                $new_user->email = !empty($user_profile->email) ? $user_profile->email : $this->project_auth['email'];
 
                if (empty($new_user->email))
                {
                    $this->flashSession->error($this->mes->_("auth.your_email_address_does_not_match_add_emai"));
 
                    return $this->response->redirect('post/project');
                }
 
                // dublicate email
                $dublicate_email = User::count([
                    'conditions' => 'email = :email:',
                    'bind'       => ['email' => $new_user->email]
                ]);
 
                if ($dublicate_email > 0)
                {
                    $this->flashSession->error($this->mes->_("auth.user_with_email_address_already_exists"));
 
                    return $this->response->redirect('post/project');
                }
 
                if (!empty($user_profile->username))
                {
                    $username = $user_profile->username;
                } else
                {
                    $username = $this->helpers->alias($user_profile->displayName);
                }
 
                // dublicate username
                $dublicate_username = User::count([
                    'conditions' => 'username = :username:',
                    'bind'       => ['username' => $username]
                ]);
 
                if ($dublicate_username > 0)
                {
                    $this->flashSession->error($this->mes->_("auth.user_with_this_username_already_exists"));
 
                    return $this->response->redirect('post/project');
                }
 
                $new_user->username   = !empty($username) ? $username : $this->public_auth['username'];
                $new_user->first_name =
                    !empty($user_profile->firstName) ? $user_profile->firstName : $this->public_auth['first_name'];
                $new_user->last_name  = !empty($user_profile->lastName) ? $user_profile->lastName : ' ';
                $new_user->city       = $user_profile->city;
                $new_user->biography  = $user_profile->description;
                $new_user->password   = $this->helpers->generate_code_i();
                $new_user->group_id   = 1;
 
                if ($new_user->save())
                {
                    // add social user link
                    $oauth_user             = new OauthUsers();
                    $oauth_user->user_id    = $new_user->user_id;
                    $oauth_user->identifier = $user_profile->identifier;
                    $oauth_user->provider   = $provider;
                    $oauth_user->save();
 
                    // Auth user
                    $this->auth->authUserById($new_user->user_id);
 
                    $this->flashSession->success($this->mes->_("auth.successfully_signed_system"));
 
                } else
                {
                    //@@TODO output flash error
                    if (APPLICATION_ENV == 'development')
                    {
                        $messages = $new_user->getMessages();
 
                        $out_mes = '';
 
                        foreach ($messages as $message)
                        {
                            $out_mes = $message . "\n";
                        }
                        $this->flashSession->error($out_mes);
                    } else
                    {
                        $this->flashSession->error($this->mes->_("auth.registration_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
                    }
                }
 
                return $this->response->redirect('post/project');
            }
 
        } catch (\Exception $e)
        {
            $this->logger->error('3) ' . $e->getMessage());
            $this->flashSession->error($this->mes->_("auth.isp_connection_error") . ' ' . $this->mes->_("main.please_contact_administrator"));
 
            return $this->response->redirect('post/project');
        }
 
    }
 
 
#4Frontend\Controller\AuthController->hybridauthAction(/socialauth)
#5Phalcon\Dispatcher->dispatch()
#6Phalcon\Mvc\Application->handle(null)
/home/udiospa/public_html/vendor/ovr/phalcony/src/Application.php (183)
<?php
/**
 * @author: Patsura Dmitry http://github.com/ovr <talk@dmtry.me>
 */
 
namespace Phalcony;
 
use Phalcon\Events\Manager as EventsManager;
use Phalcony\Stdlib\Hydrator\ClassMethods;
use InvalidArgumentException;
 
class Application extends \Phalcon\Mvc\Application
{
    const ENV_PRODUCTION = 'production';
    const ENV_STAGING = 'staging';
    const ENV_TESTING = 'testing';
    const ENV_DEVELOPMENT = 'development';
 
    /**
     * @var array
     */
    protected $configuration;
 
    /**
     * @var string
     */
    protected $env;
 
    /**
     * @param string $env
     * @param array $configuration
     * @param \Phalcon\DiInterface $di
     * @throws \Exception
     */
    public function __construct($env, array $configuration, \Phalcon\DiInterface $di = null)
    {
        $this->env = strtolower($env);
        $this->configuration = $configuration;
 
        switch ($this->env) {
            case self::ENV_PRODUCTION:
            case self::ENV_STAGING:
                ini_set('display_errors', 0);
                ini_set('display_startup_errors', 0);
                error_reporting(0);
                break;
            case self::ENV_TESTING:
            case self::ENV_DEVELOPMENT:
                ini_set('display_errors', 1);
                ini_set('display_startup_errors', 1);
                error_reporting(-1);
                break;
            default:
                throw new \Exception('Wrong application $env passed: ' . $env);
        }
 
        if (is_null($di)) {
            $di = new \Phalcon\DI\FactoryDefault();
        }
 
        parent::__construct($di);
    }
 
    /**
     * Register loader
     */
    protected function registerLoader()
    {
        $config = &$this->configuration;
 
        $loader = new \Phalcon\Loader();
 
        if (isset($config['application']['registerNamespaces'])) {
            $loadNamespaces = $config['application']['registerNamespaces'];
        } else {
            $loadNamespaces = array();
        }
 
        foreach ($config['application']['modules'] as $module => $enabled) {
            $moduleName = ucfirst($module);
            $loadNamespaces[$moduleName . '\Model'] = APPLICATION_PATH . '/modules/' . $module . '/models/';
            $loadNamespaces[$moduleName . '\Service'] = APPLICATION_PATH . '/modules/' . $module . '/services/';
        }
 
        if (isset($config['application']['registerDirs'])) {
            $loader->registerDirs($config['application']['registerDirs']);
        }
 
        $loader->registerNamespaces($loadNamespaces)
            ->register();
 
    }
 
    /**
     * Register di services
     *
     * @throws \Exception
     */
    public function registerServices()
    {
        $di = $this->getDI();
 
        if (isset($this->configuration['services'])) {
            if (!is_array($this->configuration['services'])) {
                throw new \Exception('Config[services] must be an array');
            }
 
            if (count($this->configuration['services']) > 0) {
                foreach ($this->configuration['services'] as $serviceName => $serviceParameters) {
                    $class = $serviceParameters['class'];
 
                    $shared = false;
                    $service = false;
 
                    if (isset($serviceParameters['shared'])) {
                        $shared = (boolean) $serviceParameters['shared'];
                    }
 
                    if (is_callable($class)) {
                        $shared = true;
                        $service = $class($this);
                    } else if (is_object($class)) {
                        $shared = true;
                        $service = $class;
                    } else if (isset($serviceParameters['__construct'])) {
                        $shared = true;
 
                        if (!is_array($serviceParameters)) {
                            throw new \Exception('Parameters for service : "' . $serviceName . '" must be array');
                        }
 
                        $reflector = new \ReflectionClass($class);
                        $service = $reflector->newInstanceArgs($serviceParameters['__construct']);
                    } else {
                        if ($shared) {
                            $service = new $class();
                        } else {
                            $service = $class;
                        }
                    }
 
                    if (isset($serviceParameters['parameters'])) {
                        if ($shared === false) {
                            throw new \Exception('Service: "' . $serviceName . '" with parameters must be shared');
                        }
 
                        $service = ClassMethods::hydrate($serviceParameters['parameters'], $service);
 
                        $di->set($serviceName, $service, $shared);
                    }
 
                    $di->set($serviceName, $service, $shared);
                }
            }
        }
    }
 
    /**
     * @return $this
     * @throws \Exception
     */
    public function bootstrap()
    {
        $this->registerLoader();
        $this->registerModules($this->configuration['application']['modules']);
 
        $eventsManager = new EventsManager();
        $this->setEventsManager($eventsManager);
 
        $this->registerServices();
        $this->di->set('application', $this, true);
 
        return $this;
    }
 
    /**
     * Run app
     *
     * @param null $uri
     */
    public function run($uri = null)
    {
        $this->handle($uri)->send();
    }
 
    /**
     * @return string
     */
    public function getEnv()
    {
        return $this->env;
    }
 
    /**
     * @return array
     */
    public function getConfiguration()
    {
        return $this->configuration;
    }
 
    /**
     * Get custom service parameters
     *
     * @param $serviceName
     * @return mixed
     */
    public function getParameters($serviceName)
    {
        if (isset($this->configuration['parameters'][$serviceName])) {
            return $this->configuration['parameters'][$serviceName];
        }
 
        throw new InvalidArgumentException('Wrong service : '.$serviceName.' passed to fetch from parameters');
    }
#7Phalcony\Application->run()
/home/udiospa/public_html/public/index.php (17)
<?php
/**
 * @author Patsura Dmitry https://github.com/ovr <talk@dmtry.me>
 */
error_reporting(E_ALL);
ini_set("display_errors", 1);
 
define('ROOT_PATH', dirname(dirname(__FILE__)));
define('APPLICATION_PATH', dirname(dirname(__FILE__)) . '/application');
define('PUBLIC_PATH', dirname(__FILE__));
define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development');  // production or development
 
require_once APPLICATION_PATH . "/../vendor/autoload.php";
$config = include APPLICATION_PATH . "/config/core.php";
 
$application = new \Phalcony\Application(APPLICATION_ENV, $config);
Phalcon Framework 2.0.13