Example #1
0
 /**
  * Method response
  * Return response in json, HTTP Status and exit system
  * @author Bruno Oliveira <*****@*****.**>
  * @access public
  * @return string
  */
 public static function response($response, $httpStatus = null, $break = true)
 {
     if (!empty($httpStatus)) {
         header("HTTP/1.1 {$httpStatus}");
     }
     echo Utils::jsonEncode($response);
     if ($break) {
         exit;
     }
 }
 /**
  * Method methodGetFt
  * Gera método geters para foreign table
  * @author Bruno Oliveira <*****@*****.**>
  */
 private function methodGetFt($property, $ft, $ftPhpName = null, $class)
 {
     $ftName = empty($ftPhpName) ? $ft : $ftPhpName;
     $ftName = Utils::snakeToCamelCase($ftName);
     $ft = Utils::snakeToCamelCase($ft);
     $property = lcfirst(Utils::snakeToCamelCase($property));
     $v = "\t/**";
     $v .= "\n\t * Method get{$ftName}";
     $v .= "\n\t * Obtêm o objeto " . lcfirst($ft);
     $v .= "\n\t */";
     $v .= "\n\tpublic function get{$ftName} ()";
     $v .= "\n\t{";
     $v .= "\n\t\treturn new {$class}(\$this->{$property});";
     $v .= "\n\t}";
     $v .= "\n\n";
     $this->methodsGeters .= $v;
 }
Example #3
0
 /**
  * Method update
  * Deleta o objeto do banco de dados
  * @author Bruno Oliveira <*****@*****.**>
  * @return bool
  */
 public function update()
 {
     $primaryKey = $this->getPrimaryKey();
     $class = get_class($this);
     $class = explode('\\', $class);
     $class = "{$class['0']}\\Traits\\Trait{$class['1']}";
     $r = new ReflectionClass($class);
     $vars = get_object_vars($this);
     $varsDB = array();
     foreach ($vars as $key => $val) {
         if ($r->hasProperty($key) && isset($val) && $key != $primaryKey) {
             $varsDB[Utils::camelToSnakeCase($key)] = $val;
         }
     }
     $conn = self::conn();
     $conn->table($this->getTable());
     if (!is_null($primaryKey) && isset($vars[lcfirst(Utils::snakeToCamelCase($primaryKey))])) {
         $conn->where($primaryKey, $vars[lcfirst(Utils::snakeToCamelCase($primaryKey))]);
     }
     $conn->update($varsDB);
     $conn->cleanQuery();
 }
Example #4
0
 /**
  * Method route
  * Intancia as classes dinâmicamente conforme rota
  * @author Bruno Oliveira <*****@*****.**>
  */
 private function route()
 {
     if (!isset($_GET['url'])) {
         $index = isset(self::$route['index']) ? self::$route['index'] : null;
         $this->routeLocation($index);
     } else {
         $queryStrings = array_filter(explode('/', $_GET['url']));
         $nameClass = 'Controller\\' . ucfirst(Utils::hiphenToCamelCase($queryStrings[0]));
         if (!class_exists($nameClass)) {
             throw new EasyFastException("Class \"{$nameClass}\" not found.");
         }
         $class = new $nameClass();
         if (count($queryStrings) > 1) {
             $nameMethod = Utils::hiphenToCamelCase($queryStrings[1]);
             if (method_exists($class, $nameMethod)) {
                 unset($queryStrings[0]);
                 unset($queryStrings[1]);
                 call_user_func_array(array($class, $nameMethod), $queryStrings);
             } else {
                 throw new EasyFastException("Method \"{$nameMethod}\" not found.");
             }
         } else {
             if (method_exists($class, 'view')) {
                 $class->view();
             } else {
                 throw new EasyFastException('Error generating display.');
             }
         }
     }
 }
Example #5
0
 /**
  * Method stopSystem
  * Para a execução do sistema, envia status http e retorna json com mensagem de erro
  * @author Bruno Oliveira <*****@*****.**>
  * @param string $msg
  */
 public function stopSystem($msg)
 {
     header('HTTP/1.1 401');
     echo Utils::jsonEncode("Status => Error | Message => {$msg}");
     die;
 }
Example #6
0
 /**
  * Send Message clients
  *
  * @param $message
  * @param null $client
  * @param bool|true $mask
  * @return bool
  */
 public function sendMessage($message, $client = null, $mask = true)
 {
     if ($mask) {
         $dataMessage = Utils::jsonEncode($message);
         if (json_last_error() == JSON_ERROR_NONE) {
             $message = $dataMessage;
         }
         $message = $this->mask($message);
     }
     if (is_null($client)) {
         foreach ($this->clients as $changedSocket) {
             @socket_write($changedSocket, $message, strlen($message));
         }
     } else {
         @socket_write($client, $message, strlen($message));
     }
     return true;
 }