Esempio n. 1
0
 /**
  * 
  * Função de faz a conexão com o banco de dados.
  * 
  * @return object
  */
 public static function db()
 {
     if (!isset(self::$instance)) {
         try {
             self::$instance = new \PDO(Configure::read('database.drive') . ':host=' . Configure::read('database.host') . ';dbname=' . Configure::read('database.banco'), Configure::read('database.usuario'), Configure::read('database.senha'), [\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", \PDO::ATTR_PERSISTENT => true]);
             self::$instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         } catch (\PDOException $exception) {
             $ex = new \Core\MyException();
             $ex->show_exception($exception);
         } catch (\Exception $exception) {
             $ex = new \Core\MyException();
             $ex->show_exception($exception);
         }
     }
     return self::$instance;
 }
Esempio n. 2
0
 /**
  * Executa as chamadas dos dados referente as informações vido da navegação.
  */
 public function run()
 {
     $this->controller = $this->request->controller;
     $this->action = $this->request->action;
     if (!isset($this->uri)) {
         $this->uri = [];
     } else {
         $this->uri = array_slice($this->uri, 2);
     }
     $path = '';
     if (count($this->path) > 0) {
         $path = implode('\\', $this->path);
         if (trim($path) != '') {
             $path = Inflector::camelize($path) . '\\';
         }
     }
     $controller = 'App\\Controller\\' . $path . $this->controller . 'Controller';
     $class_name = ROOT . str_replace('\\', DS, $controller) . '.php';
     $class_name = str_replace(DS . 'App' . DS, DS . 'src' . DS, $class_name);
     if (!file_exists($class_name)) {
         $ex = new \Core\MyException();
         $ex->layout = 'default';
         $ex->show_404('pagina não localizada.');
     } else {
         $controller = new $controller($this->request, new Session(), new Auth());
         $action = $this->action;
         call_user_func_array([$controller, 'beforeController'], $this->uri);
         if (method_exists($controller, $action)) {
             call_user_func_array([$controller, $action], $this->uri);
         } else {
             call_user_func_array([$controller, '_error'], $this->uri);
         }
         call_user_func_array([$controller, 'afterController'], $this->uri);
         call_user_func_array([$controller, 'beforeRender'], $this->uri);
         $controller->render();
     }
 }
Esempio n. 3
0
 /**
  * 
  * função que faz uma consulta no banco de dados.
  * 
  * @return object retorna um objeto da classe
  */
 public function find(array $conditions = [])
 {
     try {
         $this->limit(1);
         $return = $this->all($conditions);
         if (!empty($return)) {
             $this->total_registro = 1;
             return $return[0];
         }
         return false;
     } catch (\PDOException $exception) {
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
     } catch (\Exception $exception) {
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
     }
 }
Esempio n. 4
0
 /**
  * Initiate a connection to an SMTP server.
  * Overrides the original smtpConnect method to add support for OAuth.
  * @param array $options An array of options compatible with stream_context_create()
  * @return bool
  * @throws null
  * @throws Exception
  * @uses SMTP
  * @access public
  */
 public function smtpConnect($options = [])
 {
     if (is_null($this->smtp)) {
         $this->smtp = $this->getSMTPInstance();
     }
     if (is_null($this->oauth)) {
         $this->oauth = $this->getOAUTHInstance();
     }
     // Already connected?
     if ($this->smtp->connected()) {
         return true;
     }
     $this->smtp->setTimeout($this->Timeout);
     $this->smtp->setDebugLevel($this->SMTPDebug);
     $this->smtp->setDebugOutput($this->Debugoutput);
     $this->smtp->setVerp($this->do_verp);
     $hosts = explode(';', $this->Host);
     $lastexception = null;
     foreach ($hosts as $hostentry) {
         $hostinfo = [];
         if (!preg_match('/^((ssl|tls):\\/\\/)*([a-zA-Z0-9\\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
             // Not a valid host entry
             continue;
         }
         // $hostinfo[2]: optional ssl or tls prefix
         // $hostinfo[3]: the hostname
         // $hostinfo[4]: optional port number
         // The host string prefix can temporarily override the current setting for SMTPSecure
         // If it's not specified, the default value is used
         $prefix = '';
         $secure = $this->SMTPSecure;
         $tls = $this->SMTPSecure == 'tls';
         if ('ssl' == $hostinfo[2] or '' == $hostinfo[2] and 'ssl' == $this->SMTPSecure) {
             $prefix = 'ssl://';
             $tls = false;
             // Can't have SSL and TLS at the same time
             $secure = 'ssl';
         } elseif ($hostinfo[2] == 'tls') {
             $tls = true;
             // tls doesn't use a prefix
             $secure = 'tls';
         }
         //Do we need the OpenSSL extension?
         $sslext = defined('OPENSSL_ALGO_SHA1');
         if ('tls' === $secure or 'ssl' === $secure) {
             //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
             if (!$sslext) {
                 throw new Exception($this->lang('extension_missing') . 'openssl', self::STOP_CRITICAL);
             }
         }
         $host = $hostinfo[3];
         $port = $this->Port;
         $tport = (int) $hostinfo[4];
         if ($tport > 0 and $tport < 65536) {
             $port = $tport;
         }
         if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
             try {
                 if ($this->Helo) {
                     $hello = $this->Helo;
                 } else {
                     $hello = $this->serverHostname();
                 }
                 $this->smtp->hello($hello);
                 //Automatically enable TLS encryption if:
                 // * it's not disabled
                 // * we have openssl extension
                 // * we are not already using SSL
                 // * the server offers STARTTLS
                 if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
                     $tls = true;
                 }
                 if ($tls) {
                     if (!$this->smtp->startTLS()) {
                         throw new Exception($this->lang('connect_host'));
                     }
                     // We must resend HELO after tls negotiation
                     $this->smtp->hello($hello);
                 }
                 if ($this->SMTPAuth) {
                     if (!$this->smtp->authenticate($this->Username, $this->Password, $this->AuthType, $this->Realm, $this->Workstation, $this->oauth)) {
                         throw new Exception($this->lang('authenticate'));
                     }
                 }
                 return true;
             } catch (Exception $exception) {
                 $lastexception = $exception;
                 $this->edebug($exception->getMessage());
                 // We must have connected, but then failed TLS or Auth, so close connection nicely
                 $this->smtp->quit();
                 $ex = new \Core\MyException();
                 $ex->show_exception($exception);
             }
         }
     }
     // If we get here, all connection attempts have failed, so close connection hard
     $this->smtp->close();
     // As we've caught all exceptions, just report whatever the last one was
     if ($this->exceptions and !is_null($lastexception)) {
         throw $lastexception;
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Cria um arquivo de cache
  * 
  * @uses Cache::generateFileLocation() para gerar o local do arquivo de cache
  * 
  * @param string $key Uma chave para identificar o arquivo
  * @param string $content Conteúdo do arquivo de cache
  * 
  * @return boolean Se o arquivo foi criado
  */
 protected function createCacheFile($key, $content)
 {
     $filename = $this->generateFileLocation($key);
     try {
         $file = file_put_contents($filename, $content);
         if (!$file) {
             throw new \Exception('Não foi possível criar o arquivo de cache');
         }
         return $file;
     } catch (\Exception $exception) {
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
     }
 }
Esempio n. 6
0
 /**
  * Exception Handler
  *
  * Sends uncaught exceptions to the logger and displays them
  * only if display_errors is On so that they don't show up in
  * production environments.
  *
  * @param	Exception	$exception
  * @return	void
  */
 function _exception_handler($exception)
 {
     $_error = new Core\MyException();
     // Should we display the error?
     if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) {
         $_error->show_exception($exception);
     }
     exit(1);
     // EXIT_ERROR
 }
Esempio n. 7
0
 /**
  * 
  * Carrega os layout junto com as views prontas para exibir na tela
  * 
  * @throws MyException
  */
 private function renderlayout($layout)
 {
     try {
         $v = ROOT . 'src' . DS . 'Template' . DS . 'Layouts' . DS . 'Email' . DS . $layout . '.php';
         if (!file_exists($v)) {
             throw new \Exception('O Layout "' . $v . '" não localizado.', 500);
         }
         ob_start();
         extract($this->data);
         include $v;
         $layout = ob_get_contents();
         ob_clean();
         return $layout;
     } catch (\Exception $exception) {
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
     }
 }
Esempio n. 8
0
 /**
  * Encode a file attachment in requested format.
  * Returns an empty string on failure.
  * @param string $path The full path to the file
  * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
  * @throws Exception
  * @access protected
  * @return string
  */
 protected function encodeFile($path, $encoding = 'base64')
 {
     try {
         if (!is_readable($path)) {
             throw new \Exception($this->lang('file_open') . $path, self::STOP_CONTINUE);
         }
         $file_buffer = file_get_contents($path);
         $file_buffer = $this->encodeString($file_buffer, $encoding);
         return $file_buffer;
     } catch (\Exception $exception) {
         $this->setError($exception->getMessage());
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
         return '';
     }
 }
Esempio n. 9
0
 /**
  * 
  * Carrega parte de um html para ser usado em mais de uma view ou layout
  * 
  * @param string $view
  * @param array $dados
  * @throws MyException
  */
 public function element($view, array $dados = [])
 {
     try {
         $v = ROOT . 'src' . DS . 'Template' . DS . 'Elements' . DS . $view . '.php';
         if (!file_exists($v)) {
             throw new MyException('Elemento "' . $v . '" não localizada.');
         }
         extract($dados);
         include $v;
     } catch (\Exception $exception) {
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
     }
 }
Esempio n. 10
0
 /**
  * Disconnect from the POP3 server.
  * @access public
  */
 public function disconnect()
 {
     $this->sendString('QUIT');
     //The QUIT command may cause the daemon to exit, which will kill our connection
     //So ignore errors here
     try {
         @fclose($this->pop_conn);
     } catch (Exception $exception) {
         $ex = new \Core\MyException();
         $ex->show_exception($exception);
         //Do nothing
     }
 }