public function init(array $options = []) { $this->default = array_merge($this->default, Configure::read('auth.' . $this->config)); $this->default = Hash::merge($this->default, $options); $table = '\\App\\Model\\Table\\' . $this->default['model'] . 'Table'; $this->model = new $table(); $this->keyName = $this->default['keyName']; }
public function up($file = '') { if (trim($file) == '') { $file = Configure::read('database.banco') . '_' . date('Y_m_d_H_i_s'); } $file = ROOT . 'src' . DS . 'dump' . DS . trim($file, '.sql') . '.sql'; if (file_exists($file)) { $q = 'mysqldump -u ' . Configure::read('database.usuario') . ' ' . (Configure::read('database.senha') != '' ? '-p' . Configure::read('database.senha') : '') . ' ' . Configure::read('database.banco') . ' < ' . $file; $r = exec($q); return (bool) (stripos($r, '-- Dump completed') !== false ? true : false); } return null; }
/** * * 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; }
/** * * função que exclui a tabela do banco de dados * * @return boolean */ public function columnsName() { $c = $this->pdo->query('SHOW FULL COLUMNS FROM ' . Configure::read('database.banco') . '.' . $this->tabela)->fetchAll(\PDO::FETCH_OBJ); if (count($c)) { $co = []; foreach ($c as $key => $value) { $co[$value->Field] = $value->Field; } return $co; } return null; }
/** * Função de auto execução ao startar a classe. */ public function __construct() { Configure::load('database'); $this->log = (bool) Configure::read('database.log'); $class = explode('\\', get_class($this)); $class = end($class); $this->classe = substr($class, 0, -5) . 'Entity'; $this->alias = substr($class, 0, -5); $this->classe = '\\App\\Model\\Entity\\' . $this->classe; $this->pdo = Conection::db(); $this->_cache = new Cache('model' . DS . $this->tabela); $this->_cache->setTime(Configure::read('database.cacheTime')); $this->cache = (bool) Configure::read('database.cache'); $this->schema = $this->schema()->columnsTypes(); $this->_conditions = new Conditions($this->tabela, $this->alias, $this->schema()); }
private function _create() { if ($this->is_session_started()) { Configure::load('session'); foreach (Configure::read('session') as $key => $value) { ini_set($key, $value); } } @session_start(); }
/** * * Faz o tratamento das url para definar os dados de rotas a ser usados. * * @param string $uriPath */ public function match($uriPath) { $uriPath = '/' . trim($uriPath, '/'); Configure::load('rotas'); $rotas = Configure::read('rotas'); if (count($rotas) > 0) { foreach ($rotas as $route => $actualPage) { $route_regex = preg_replace('@:[^/]+@', '([^/]+)', $route); if (!preg_match('@' . $route_regex . '@', $uriPath, $matches)) { continue; } $r = preg_match('@' . $route_regex . '@', $route, $identifiers); if ($r > 0) { if ($identifiers[0] === $uriPath) { $this->uri = []; foreach (explode('.', $actualPage) as $k => $v) { $this->uri[$k] = $v; } } } } } }
public function send($options, $type = 'default') { Configure::load('mail'); $config = Configure::read('mail'); if (!empty(Configure::read('Parametros.Email'))) { $config = array_merge($config, Configure::read('Parametros.Email')); } $config = $config[$type]; $mail = new PHPMailer((bool) Configure::read('app.debug')); $mail->SMTPDebug = (int) $config['Debug']; $mail->isSMTP(); $mail->Host = $config['Host']; $mail->SMTPAuth = (bool) $config['Auth']; $mail->Username = $config['Username']; $mail->Password = $config['Password']; $mail->SMTPAutoTLS = false; if ($config['AutoTls'] > 0) { $mail->SMTPSecure = $config['Secure']; $mail->SMTPAutoTLS = true; } $mail->Port = (int) $config['Port']; $mail->CharSet = $config['Charset']; //$mail->isSMTP(); // Set mailer to use SMTP //$mail->Host = 'smtp.appettosa.com.br'; // Specify main and backup server //$mail->SMTPAuth = true; // Enable SMTP authentication //$mail->Port = 587; //$mail->Username = '******'; // SMTP username //$mail->Password = '******'; // SMTP password //$mail->From = ('*****@*****.**'); //$mail->FromName = $_POST['nome']; $default = ['from' => ['mail' => '', 'title' => ''], 'add' => [], 'replyto' => [], 'cc' => [], 'bcc' => [], 'file' => [], 'html' => true, 'title' => '', 'data' => [], 'alt' => '', 'layout' => 'default', 'view' => 'default']; $options = Hash::merge($default, $options); $options['add'] = Hash::merge([-1 => [$options['from']['mail'] => $options['from']['title']]], $options['add']); $mail->setFrom($config['Username'], $config['Name']); if (count($options['add'])) { foreach ($options['add'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addAddress($k, $v); } } else { $mail->addAddress($value); } } } if (count($options['replyto'])) { foreach ($options['replyto'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addReplyTo($k, $v); } } else { $mail->addReplyTo($value); } } } if (count($options['cc'])) { foreach ($options['cc'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addCC($k, $v); } } else { $mail->addCC($value); } } } if (count($options['bcc'])) { foreach ($options['bcc'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addBCC($k, $v); } } else { $mail->addBCC($value); } } } if (count($options['file'])) { foreach ($options['file'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addAttachment($k, $v); } } else { $mail->addAttachment($value); } } } $mail->isHTML($options['html']); $this->data = $options['data']; //debug($this->data); $this->data['title'] = $options['title']; $this->loads(); $this->render($options['view']); $options['body'] = $this->renderlayout($options['layout']); $mail->Subject = $options['title']; $mail->Body = $options['body']; $mail->AltBody = $options['alt']; try { if (!$mail->send()) { return false; } else { return true; } } catch (\Exception $exception) { $this->error = $exception; $ex = new \Core\MyException(); $ex->show_exception($exception); return false; } }