From 281fe38a981e9e184f6ac565d82038700c09da48 Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Mon, 26 Dec 2022 11:18:34 +0700 Subject: [PATCH] Refactoring Array --- hungng/HungNG_CI_Base_Controllers.php | 71 +++++++++-- hungng/HungNG_CI_Base_Lib_ElasticSearch.php | 55 +++++---- hungng/HungNG_CI_Base_Lib_MongoDB.php | 76 ++++++------ hungng/HungNG_CI_Base_Module.php | 71 +++++++++-- hungng/HungNG_CI_Base_Queue_Worker.php | 4 +- hungng/HungNG_CI_Base_REST.php | 30 ++--- hungng/HungNG_Custom_Based_model.php | 2 +- hungng/HungNG_ORM_Model.php | 38 +++--- hungng/StatusCodes.php | 124 ++++++++++---------- 9 files changed, 300 insertions(+), 171 deletions(-) diff --git a/hungng/HungNG_CI_Base_Controllers.php b/hungng/HungNG_CI_Base_Controllers.php index 8033a16..4968db9 100644 --- a/hungng/HungNG_CI_Base_Controllers.php +++ b/hungng/HungNG_CI_Base_Controllers.php @@ -81,23 +81,23 @@ public function __construct() */ protected function defaultJsonResponseInfo() { - $response = [ + $response = array( 'code' => StatusCodes::HTTP_OK, 'message' => StatusCodes::$statusTexts[StatusCodes::HTTP_OK], - 'info' => [ + 'info' => array( 'name' => 'Nguyen An Hung', 'email' => 'dev@nguyenanhung.com', 'web' => 'https://nguyenanhung.com', 'blog' => 'https://blog.nguyenanhung.com', 'facebook' => 'https://facebook.com/nguyenanhung', - 'github' => 'https://github.com/nguyenanhung', - ], - 'request_data' => [ + 'github' => 'https://github.com/nguyenanhung' + ), + 'request_data' => array( 'ip' => getIPAddress(), 'user_agent' => $this->input->user_agent(true), 'request_method' => $this->input->method(true) - ] - ]; + ) + ); $this->output->set_status_header()->set_content_type('application/json', 'utf-8')->set_output(json_encode($response, JSON_PRETTY_PRINT))->_display(); exit; } @@ -372,5 +372,62 @@ protected function log($name = '', $message = '', $context = array(), $inputLeve log_message('error', $exception->getTraceAsString()); } } + + /** + * Function opcache_flush_reset + * + * @author : 713uk13m + * @copyright: 713uk13m + * @time : 26/12/2022 01:36 + */ + protected function opcache_flush_reset() + { + if (function_exists('opcache_reset') && is_cli()) { + opcache_reset(); + } else { + show_404(); + } + } + + /** + * Function default_base_flush_logs + * + * @author : 713uk13m + * @copyright: 713uk13m + * @time : 26/12/2022 04:29 + */ + protected function default_base_flush_logs() + { + if (is_cli()) { + try { + $file = new \nguyenanhung\MyDebug\Manager\File(); + $file->setInclude(array('*.log', '*.txt', 'log-*.php')); + $response = array( + 'status' => 'OK', + 'time' => date('Y-m-d H:i:s'), + 'data' => array( + 'logs' => $file->cleanLog(dirname(__DIR__) . '/logs', 7), + 'logs-data' => $file->cleanLog(dirname(__DIR__) . '/logs-data', 7) + ) + ); + log_message('debug', 'Clean Log Result: ' . json_encode($response)); + $output = defined('JSON_PRETTY_PRINT') ? json_encode($response, JSON_PRETTY_PRINT) : json_encode($response); + $this->output->set_status_header()->set_content_type('application/json', 'utf-8')->set_output($output . PHP_EOL)->_display(); + exit; + } catch (Exception $e) { + $message = 'Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage(); + log_message('error', $message); + } + } else { + $info = array( + 'method' => $this->input->method(true), + 'ip_address' => $this->input->ip_address(), + 'user_agent' => $this->input->user_agent(true), + 'request_headers' => $this->input->request_headers(true) + ); + log_message('error', json_encode($info)); + show_404(); + } + } } } diff --git a/hungng/HungNG_CI_Base_Lib_ElasticSearch.php b/hungng/HungNG_CI_Base_Lib_ElasticSearch.php index 7d398d7..9ab94ae 100644 --- a/hungng/HungNG_CI_Base_Lib_ElasticSearch.php +++ b/hungng/HungNG_CI_Base_Lib_ElasticSearch.php @@ -45,9 +45,9 @@ public function exists_index($index) { $status = 404; if ($index) { - $params = ['index' => $index]; + $params = array('index' => $index); $response = $this->client->indices()->exists($params); - $status = $response->getStatusCode(); + $status = $response->getStatusCode(); } return $status; @@ -55,13 +55,13 @@ public function exists_index($index) public function create_index($index, $body) { - $params = ['index' => $index, 'body' => $body]; + $params = array('index' => $index, 'body' => $body); $response = $this->client->indices()->create($params); } public function refresh_index($index) { - $params = ['index' => $index]; + $params = array('index' => $index); $response = $this->client->indices()->refresh($params); } @@ -70,7 +70,7 @@ public function delete_index($index) if (!$index) { return false; } - $params = ['index' => $index]; + $params = array('index' => $index); try { $response = $this->client->indices()->delete($params); } catch (Exception $e) { @@ -82,7 +82,11 @@ public function delete_index($index) public function get_found_document($index, $type, $id) { //db - collection - id - $params = ['index' => $index, 'type' => $type, 'id' => $id]; + $params = array( + 'index' => $index, + 'type' => $type, + 'id' => $id + ); $results = $this->client->get($params); return $results['found']; @@ -90,60 +94,70 @@ public function get_found_document($index, $type, $id) public function exists_document($index, $type, $id) { - $params = ['index' => $index, 'type' => $type, 'id' => $id]; + $params = array( + 'index' => $index, + 'type' => $type, + 'id' => $id + ); return $this->client->exists($params); } public function create_document($index, $type, $id, $body) { - $params = [ + $params = array( 'index' => $index, 'type' => $type, 'id' => $id, - 'body' => $body]; + 'body' => $body + ); return $this->client->index($params); } public function update_document($index, $type, $id, $body) { - $params = [ + $params = array( 'index' => $index, 'type' => $type, 'id' => $id, - 'body' => $body]; + 'body' => $body + ); return $this->client->update($params); } public function delete_document($index, $type, $id) { - $params = [ + $params = array( 'index' => $index, 'type' => $type, 'refresh' => 'wait_for', //or true - 'id' => $id]; + 'id' => $id + ); return $this->client->delete($params); } public function search_document($index, $type, $from, $size, $query, $all) { - $params = [ + $params = array( 'index' => $index, 'type' => $type, - 'body' => [ + 'body' => array( 'from' => $from, 'size' => $size, - 'query' => $query]]; + 'query' => $query + ) + ); if ($all) { - $params = [ + $params = array( 'index' => $index, 'type' => $type, 'from' => $from, 'size' => $size, - 'body' => ['query' => $query]]; + 'body' => array('query' => $query) + ); } return $this->client->search($params); @@ -153,10 +167,11 @@ public function count_documents($index, $type, $query) { $exists_index = $this->exists_index($index); if ($exists_index === 200) { - $params = [ + $params = array( 'index' => $index, 'type' => $type, - 'body' => ['query' => $query]]; + 'body' => array('query' => $query) + ); $response = $this->client->count($params); } else { $response['count'] = 0; diff --git a/hungng/HungNG_CI_Base_Lib_MongoDB.php b/hungng/HungNG_CI_Base_Lib_MongoDB.php index 2871569..c73db69 100644 --- a/hungng/HungNG_CI_Base_Lib_MongoDB.php +++ b/hungng/HungNG_CI_Base_Lib_MongoDB.php @@ -69,7 +69,7 @@ public function __construct($param) $this->CI =& get_instance(); $this->CI->load->config('mongo_db'); $this->config = $this->CI->config->item('mongo_db'); - $this->param = $param; + $this->param = $param; $this->connect(); } @@ -725,7 +725,7 @@ public function like($field = "", $value = "", $flags = "i", $enable_start_wildc if ($enable_end_wildcard !== true) { $value .= "$"; } - $regex = "/$value/$flags"; + $regex = "/$value/$flags"; $this->wheres[$field] = new MongoDB\BSON\Regex($regex); return ($this); @@ -748,17 +748,17 @@ public function get($collection = "") try { - $read_concern = new MongoDB\Driver\ReadConcern($this->read_concern); + $read_concern = new MongoDB\Driver\ReadConcern($this->read_concern); $read_preference = new MongoDB\Driver\ReadPreference($this->read_preference); - $options = array(); - $options['projection'] = $this->selects; - $options['sort'] = $this->sorts; - $options['skip'] = (int) $this->offset; - $options['limit'] = (int) $this->limit; + $options = array(); + $options['projection'] = $this->selects; + $options['sort'] = $this->sorts; + $options['skip'] = (int) $this->offset; + $options['limit'] = (int) $this->limit; $options['readConcern'] = $read_concern; - $query = new MongoDB\Driver\Query($this->wheres, $options); + $query = new MongoDB\Driver\Query($this->wheres, $options); $cursor = $this->db->executeQuery($this->database . "." . $collection, $query, $read_preference); // Clear @@ -830,17 +830,17 @@ public function find_one($collection = "") try { - $read_concern = new MongoDB\Driver\ReadConcern($this->read_concern); + $read_concern = new MongoDB\Driver\ReadConcern($this->read_concern); $read_preference = new MongoDB\Driver\ReadPreference($this->read_preference); - $options = array(); - $options['projection'] = $this->selects; - $options['sort'] = $this->sorts; - $options['skip'] = (int) $this->offset; - $options['limit'] = (int) 1; + $options = array(); + $options['projection'] = $this->selects; + $options['sort'] = $this->sorts; + $options['skip'] = (int) $this->offset; + $options['limit'] = (int) 1; $options['readConcern'] = $read_concern; - $query = new MongoDB\Driver\Query($this->wheres, $options); + $query = new MongoDB\Driver\Query($this->wheres, $options); $cursor = $this->db->executeQuery($this->database . "." . $collection, $query, $read_preference); // Clear @@ -892,19 +892,19 @@ public function count($collection = "") try { - $read_concern = new MongoDB\Driver\ReadConcern($this->read_concern); + $read_concern = new MongoDB\Driver\ReadConcern($this->read_concern); $read_preference = new MongoDB\Driver\ReadPreference($this->read_preference); - $options = array(); - $options['projection'] = array('_id' => 1); - $options['sort'] = $this->sorts; - $options['skip'] = (int) $this->offset; - $options['limit'] = (int) $this->limit; + $options = array(); + $options['projection'] = array('_id' => 1); + $options['sort'] = $this->sorts; + $options['skip'] = (int) $this->offset; + $options['limit'] = (int) $this->limit; $options['readConcern'] = $read_concern; - $query = new MongoDB\Driver\Query($this->wheres, $options); + $query = new MongoDB\Driver\Query($this->wheres, $options); $cursor = $this->db->executeQuery($this->database . "." . $collection, $query, $read_preference); - $array = $cursor->toArray(); + $array = $cursor->toArray(); // Clear $this->_clear(); @@ -1328,7 +1328,7 @@ public function delete($collection = "") } $options = array('limit' => true); - $bulk = new MongoDB\Driver\BulkWrite(); + $bulk = new MongoDB\Driver\BulkWrite(); $bulk->delete($this->wheres, $options); $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); @@ -1375,7 +1375,7 @@ public function delete_all($collection = "") } $options = array('limit' => false); - $bulk = new MongoDB\Driver\BulkWrite(); + $bulk = new MongoDB\Driver\BulkWrite(); $bulk->delete($this->wheres, $options); $writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000); @@ -1522,7 +1522,7 @@ private function convert_document_id($document) if ($this->legacy_support === true && isset($document['_id']) && $document['_id'] instanceof MongoDB\BSON\ObjectId) { $new_id = $document['_id']->__toString(); unset($document['_id']); - $document['_id'] = new \stdClass(); + $document['_id'] = new \stdClass(); $document['_id']->{'$id'} = $new_id; } @@ -1608,9 +1608,9 @@ public function add_index($collection = "", $keys = array(), $options = array()) $keys[$col] = 1; } } - $command = array(); + $command = array(); $command['createIndexes'] = $collection; - $command['indexes'] = array($keys); + $command['indexes'] = array($keys); return $this->command($command); } @@ -1636,9 +1636,9 @@ public function remove_index($collection = "", $name = "") show_error("Index could not be removed from MongoDB Collection because no index name were specified", 500); } - $command = array(); + $command = array(); $command['dropIndexes'] = $collection; - $command['index'] = $name; + $command['index'] = $name; return $this->command($command); } @@ -1657,7 +1657,7 @@ public function list_indexes($collection = "") if (empty($collection)) { show_error("No Mongo collection specified to list all indexes from", 500); } - $command = array(); + $command = array(); $command['listIndexes'] = $collection; return $this->command($command); @@ -1692,7 +1692,7 @@ public function drop_db($database = '') show_error('Failed to drop MongoDB database because name is empty', 500); } - $command = array(); + $command = array(); $command['dropDatabase'] = 1; return $this->command($command); @@ -1713,7 +1713,7 @@ public function drop_collection($col = '') show_error('Failed to drop MongoDB collection because collection name is empty', 500); } - $command = array(); + $command = array(); $command['drop'] = $col; return $this->command($command); @@ -1730,10 +1730,10 @@ private function _clear() { $this->selects = array(); $this->updates = array(); - $this->wheres = array(); - $this->limit = 999999; - $this->offset = 0; - $this->sorts = array(); + $this->wheres = array(); + $this->limit = 999999; + $this->offset = 0; + $this->sorts = array(); } /** diff --git a/hungng/HungNG_CI_Base_Module.php b/hungng/HungNG_CI_Base_Module.php index 794a24c..02f1303 100644 --- a/hungng/HungNG_CI_Base_Module.php +++ b/hungng/HungNG_CI_Base_Module.php @@ -81,23 +81,23 @@ public function __construct() */ protected function defaultJsonResponseInfo() { - $response = [ + $response = array( 'code' => StatusCodes::HTTP_OK, 'message' => StatusCodes::$statusTexts[StatusCodes::HTTP_OK], - 'info' => [ + 'info' => array( 'name' => 'Nguyen An Hung', 'email' => 'dev@nguyenanhung.com', 'web' => 'https://nguyenanhung.com', 'blog' => 'https://blog.nguyenanhung.com', 'facebook' => 'https://facebook.com/nguyenanhung', - 'github' => 'https://github.com/nguyenanhung', - ], - 'request_data' => [ + 'github' => 'https://github.com/nguyenanhung' + ), + 'request_data' => array( 'ip' => getIPAddress(), 'user_agent' => $this->input->user_agent(true), 'request_method' => $this->input->method(true) - ] - ]; + ) + ); $this->output->set_status_header()->set_content_type('application/json', 'utf-8')->set_output(json_encode($response, JSON_PRETTY_PRINT))->_display(); exit; } @@ -372,5 +372,62 @@ protected function log($name = '', $message = '', $context = array(), $inputLeve log_message('error', $exception->getTraceAsString()); } } + + /** + * Function opcache_flush_reset + * + * @author : 713uk13m + * @copyright: 713uk13m + * @time : 26/12/2022 01:36 + */ + protected function opcache_flush_reset() + { + if (function_exists('opcache_reset') && is_cli()) { + opcache_reset(); + } else { + show_404(); + } + } + + /** + * Function default_base_flush_logs + * + * @author : 713uk13m + * @copyright: 713uk13m + * @time : 26/12/2022 04:29 + */ + protected function default_base_flush_logs() + { + if (is_cli()) { + try { + $file = new \nguyenanhung\MyDebug\Manager\File(); + $file->setInclude(array('*.log', '*.txt', 'log-*.php')); + $response = array( + 'status' => 'OK', + 'time' => date('Y-m-d H:i:s'), + 'data' => array( + 'logs' => $file->cleanLog(dirname(__DIR__) . '/logs', 7), + 'logs-data' => $file->cleanLog(dirname(__DIR__) . '/logs-data', 7) + ) + ); + log_message('debug', 'Clean Log Result: ' . json_encode($response)); + $output = defined('JSON_PRETTY_PRINT') ? json_encode($response, JSON_PRETTY_PRINT) : json_encode($response); + $this->output->set_status_header()->set_content_type('application/json', 'utf-8')->set_output($output . PHP_EOL)->_display(); + exit; + } catch (Exception $e) { + $message = 'Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage(); + log_message('error', $message); + } + } else { + $info = array( + 'method' => $this->input->method(true), + 'ip_address' => $this->input->ip_address(), + 'user_agent' => $this->input->user_agent(true), + 'request_headers' => $this->input->request_headers(true) + ); + log_message('error', json_encode($info)); + show_404(); + } + } } } diff --git a/hungng/HungNG_CI_Base_Queue_Worker.php b/hungng/HungNG_CI_Base_Queue_Worker.php index 8f81b25..9b9cad8 100644 --- a/hungng/HungNG_CI_Base_Queue_Worker.php +++ b/hungng/HungNG_CI_Base_Queue_Worker.php @@ -178,7 +178,7 @@ class HungNG_CI_Base_Queue_Worker extends HungNG_CI_Base_Controllers * * @var array Worker ID => OS PID */ - protected $_pidStack = []; + protected $_pidStack = array(); public function __construct() { @@ -308,7 +308,7 @@ public function listen() $workingFlag = false; $workerCount = 0; // Clear worker stack - $this->_pidStack = []; + $this->_pidStack = array(); $costSeconds = number_format(microtime(true) - $startTime, 2, '.', ''); $this->_log("Queue Listener - Job empty"); $this->_log("Queue Listener - Stop dispatch, total cost: {$costSeconds}s"); diff --git a/hungng/HungNG_CI_Base_REST.php b/hungng/HungNG_CI_Base_REST.php index 43d0eb0..1bb8236 100644 --- a/hungng/HungNG_CI_Base_REST.php +++ b/hungng/HungNG_CI_Base_REST.php @@ -46,26 +46,26 @@ class HungNG_CI_Base_REST extends HungNG_CI_Base_Controllers * * @var array RESTful API table of routes & actions */ - protected $routes = [ + protected $routes = array( 'index' => 'index', 'store' => 'store', 'show' => 'show', 'update' => 'update', 'delete' => 'delete', - ]; + ); /** * Behaviors of actions * * @var array */ - private $behaviors = [ + private $behaviors = array( 'index' => null, 'store' => null, 'show' => null, 'update' => null, 'delete' => null, - ]; + ); /** * Pre-setting format @@ -81,10 +81,10 @@ class HungNG_CI_Base_REST extends HungNG_CI_Base_Controllers */ protected $bodyFormat = false; - /** @var \nguyenanhung\CodeIgniter\BaseREST\Request */ + /** @var \nguyenanhung\CodeIgniter\BaseREST\Request */ protected $request; - /** @var \nguyenanhung\CodeIgniter\BaseREST\Response */ + /** @var \nguyenanhung\CodeIgniter\BaseREST\Response */ protected $response; function __construct() @@ -117,7 +117,7 @@ public function route($resourceID = null) switch ($this->request->getMethod()) { case 'POST': if (!$resourceID) { - return $this->_action(['store', $this->request->getBodyParams()]); + return $this->_action(array('store', $this->request->getBodyParams())); } break; case 'PATCH': @@ -126,17 +126,17 @@ public function route($resourceID = null) return $this->_defaultAction(); } case 'PUT': - return $this->_action(['update', $resourceID, $this->request->getBodyParams()]); + return $this->_action(array('update', $resourceID, $this->request->getBodyParams())); break; case 'DELETE': - return $this->_action(['delete', $resourceID, $this->request->getBodyParams()]); + return $this->_action(array('delete', $resourceID, $this->request->getBodyParams())); break; case 'GET': default: if ($resourceID) { - return $this->_action(['show', $resourceID]); + return $this->_action(array('show', $resourceID)); } else { - return $this->_action(['index']); + return $this->_action(array('index')); } break; } @@ -178,7 +178,7 @@ public function ajax($resourceID = null) * json(false, true, 401, 'Login Required', 'Unauthorized'); * @throws \Exception */ - protected function json($data = [], $bodyFormat = null, $statusCode = null, $message = null) + protected function json($data = array(), $bodyFormat = null, $statusCode = null, $message = null) { // Check default Body Format setting if not assigning $bodyFormat = ($bodyFormat !== null) ? $bodyFormat : $this->bodyFormat; @@ -188,7 +188,7 @@ protected function json($data = [], $bodyFormat = null, $statusCode = null, $mes $data = $this->_format($statusCode, $message, $data); } else { // JSON standard of RFC4627 - $data = is_array($data) ? $data : [$data]; + $data = is_array($data) ? $data : array($data); } return $this->response->json($data, $statusCode); @@ -207,7 +207,7 @@ protected function json($data = [], $bodyFormat = null, $statusCode = null, $mes */ protected function _format($statusCode = null, $message = null, $body = false) { - $format = []; + $format = array(); // Status Code field is necessary $format['code'] = ($statusCode) ? : $this->response->getStatusCode(); @@ -238,7 +238,7 @@ protected function _format($statusCode = null, $message = null, $body = false) */ protected function pack($data, $statusCode = 200, $message = null) { - $packBody = []; + $packBody = array(); // Status Code if ($statusCode) { diff --git a/hungng/HungNG_Custom_Based_model.php b/hungng/HungNG_Custom_Based_model.php index 578e929..6653b60 100644 --- a/hungng/HungNG_Custom_Based_model.php +++ b/hungng/HungNG_Custom_Based_model.php @@ -408,7 +408,7 @@ public function get_list_distinct($field = '*') * @copyright: 713uk13m * @time : 09/13/2021 16:49 */ - public function get_data_simple_result($select = '*', $wheres = [], $size = 75, $page = 0, $orderBy = ['id' => 'DESC']) + public function get_data_simple_result($select = '*', $wheres = array(), $size = 75, $page = 0, $orderBy = array('id' => 'DESC')) { $this->db->select($select); $this->db->from($this->tableName); diff --git a/hungng/HungNG_ORM_Model.php b/hungng/HungNG_ORM_Model.php index 4c380cd..7218059 100644 --- a/hungng/HungNG_ORM_Model.php +++ b/hungng/HungNG_ORM_Model.php @@ -50,7 +50,7 @@ class HungNG_ORM_Model extends CI_Model implements ArrayAccess * * @var array Field names of columns */ - protected $fillable = []; + protected $fillable = array(); /** * Indicates if the model should be timestamped. @@ -134,17 +134,17 @@ class HungNG_ORM_Model extends CI_Model implements ArrayAccess /** * @var object database caches by database key for write */ - protected static $_dbCaches = []; + protected static $_dbCaches = array(); /** * @var object database caches by database key for read (Salve) */ - protected static $_dbrCaches = []; + protected static $_dbrCaches = array(); /** * @var object ORM schema caches by model class namespace */ - private static $_ormCaches = []; + private static $_ormCaches = array(); /** * @var bool SOFT_DELETED one time switch @@ -161,14 +161,14 @@ class HungNG_ORM_Model extends CI_Model implements ArrayAccess * * @var array */ - private $_readProperties = []; + private $_readProperties = array(); /** * ORM write properties * * @var array */ - private $_writeProperties = []; + private $_writeProperties = array(); /** * ORM self query @@ -189,7 +189,7 @@ class HungNG_ORM_Model extends CI_Model implements ArrayAccess * * @var array */ - private $_relationshipCaches = []; + private $_relationshipCaches = array(); /** * Constructor @@ -317,7 +317,7 @@ public function tableName() */ public function filters() { - return []; + return array(); } /** @@ -328,7 +328,7 @@ public function filters() */ public function rules() { - return []; + return array(); } /** @@ -342,7 +342,7 @@ public function rules() * @return boolean Result * @return mixed Data after filter ($returnData is true) */ - public function validate($attributes = [], $returnData = false) + public function validate($attributes = array(), $returnData = false) { // Data fetched by ORM or input $data = ($attributes) ? $attributes : $this->_writeProperties; @@ -356,7 +356,7 @@ public function validate($attributes = [], $returnData = false) // The ORM update will only collect rules with corresponding modified attributes. if ($this->_selfCondition) { - $newRules = []; + $newRules = array(); foreach ((array) $rules as $key => $rule) { if (isset($this->_writeProperties[$rule['field']])) { // Add into new rules for updating @@ -556,7 +556,7 @@ public function forceFind() * $this->Model->find()->where('id', 123); * $this->Model->findOne(); */ - public static function findOne($condition = []) + public static function findOne($condition = ) { if ((isset($this))) { $instance = $this; @@ -590,7 +590,7 @@ public static function findOne($condition = []) * $this->Model->find()->where_in('id', [3,21,135]); * $this->Model->findAll(); */ - public static function findAll($condition = [], $limit = null) + public static function findAll($condition = array(), $limit = null) { $instance = (isset($this)) ? $this : new static; @@ -618,7 +618,7 @@ public static function findAll($condition = [], $limit = null) return $records; } - $set = []; + $set = array(); // Each ActiveRecord foreach ((array) $records as $key => $record) { // Check primary key setting @@ -862,7 +862,7 @@ public function batchUpdate(array $dataSet, $withAll = false, $maxLength = null, * // Force delete for SOFT_DELETED mode * $this->Model->delete(123, true); */ - public function delete($condition = null, $forceDelete = false, $attributes = []) + public function delete($condition = null, $forceDelete = false, $attributes = array()) { // Check is Active Record if ($this->_readProperties) { @@ -1116,7 +1116,7 @@ public function save($runValidation = true) // Event $this->afterSave(true, $this->_readProperties); // Reset properties - $this->_writeProperties = []; + $this->_writeProperties = array(); } } else { @@ -1138,7 +1138,7 @@ public function save($runValidation = true) // Event $this->afterSave(true, $this->_readProperties); // Reset properties - $this->_writeProperties = []; + $this->_writeProperties = array(); } } @@ -1270,7 +1270,7 @@ protected function _getRelationshipProperty($method) return $this->_relationshipCaches[$method]; } - $query = call_user_func_array([$this, $method], []); + $query = call_user_func_array([$this, $method], array()); // Extract query builder injection property $modelName = isset($query->modelName) ? $query->modelName : null; @@ -1354,7 +1354,7 @@ public static function indexBy(array &$array, $key = null, $obj2Array = false) // Use model instance's primary key while no given key $key = ($key) ? : (new static())->primaryKey; - $tmp = []; + $tmp = array(); foreach ($array as $row) { // Array & Object types support if (is_object($row) && isset($row->$key)) { diff --git a/hungng/StatusCodes.php b/hungng/StatusCodes.php index d4c7e1e..2f3963f 100644 --- a/hungng/StatusCodes.php +++ b/hungng/StatusCodes.php @@ -13,69 +13,69 @@ */ class StatusCodes { - const HTTP_CONTINUE = 100; - const HTTP_SWITCHING_PROTOCOLS = 101; - const HTTP_PROCESSING = 102; // RFC2518 - const HTTP_EARLY_HINTS = 103; // RFC8297 - const HTTP_OK = 200; - const HTTP_CREATED = 201; - const HTTP_ACCEPTED = 202; - const HTTP_NON_AUTHORITATIVE_INFORMATION = 203; - const HTTP_NO_CONTENT = 204; - const HTTP_RESET_CONTENT = 205; - const HTTP_PARTIAL_CONTENT = 206; - const HTTP_MULTI_STATUS = 207; // RFC4918 - const HTTP_ALREADY_REPORTED = 208; // RFC5842 - const HTTP_IM_USED = 226; // RFC3229 - const HTTP_MULTIPLE_CHOICES = 300; - const HTTP_MOVED_PERMANENTLY = 301; - const HTTP_FOUND = 302; - const HTTP_SEE_OTHER = 303; - const HTTP_NOT_MODIFIED = 304; - const HTTP_USE_PROXY = 305; - const HTTP_RESERVED = 306; - const HTTP_TEMPORARY_REDIRECT = 307; - const HTTP_PERMANENTLY_REDIRECT = 308; // RFC7238 - const HTTP_BAD_REQUEST = 400; - const HTTP_UNAUTHORIZED = 401; - const HTTP_PAYMENT_REQUIRED = 402; - const HTTP_FORBIDDEN = 403; - const HTTP_NOT_FOUND = 404; - const HTTP_METHOD_NOT_ALLOWED = 405; - const HTTP_NOT_ACCEPTABLE = 406; - const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; - const HTTP_REQUEST_TIMEOUT = 408; - const HTTP_CONFLICT = 409; - const HTTP_GONE = 410; - const HTTP_LENGTH_REQUIRED = 411; - const HTTP_PRECONDITION_FAILED = 412; - const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; - const HTTP_REQUEST_URI_TOO_LONG = 414; - const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; - const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; - const HTTP_EXPECTATION_FAILED = 417; - const HTTP_I_AM_A_TEAPOT = 418; // RFC2324 - const HTTP_MISDIRECTED_REQUEST = 421; // RFC7540 - const HTTP_UNPROCESSABLE_ENTITY = 422; // RFC4918 - const HTTP_LOCKED = 423; // RFC4918 - const HTTP_FAILED_DEPENDENCY = 424; // RFC4918 - const HTTP_TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04 - const HTTP_UPGRADE_REQUIRED = 426; // RFC2817 - const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585 - const HTTP_TOO_MANY_REQUESTS = 429; // RFC6585 - const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 - const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451; - const HTTP_INTERNAL_SERVER_ERROR = 500; - const HTTP_NOT_IMPLEMENTED = 501; - const HTTP_BAD_GATEWAY = 502; - const HTTP_SERVICE_UNAVAILABLE = 503; - const HTTP_GATEWAY_TIMEOUT = 504; - const HTTP_VERSION_NOT_SUPPORTED = 505; + const HTTP_CONTINUE = 100; + const HTTP_SWITCHING_PROTOCOLS = 101; + const HTTP_PROCESSING = 102; // RFC2518 + const HTTP_EARLY_HINTS = 103; // RFC8297 + const HTTP_OK = 200; + const HTTP_CREATED = 201; + const HTTP_ACCEPTED = 202; + const HTTP_NON_AUTHORITATIVE_INFORMATION = 203; + const HTTP_NO_CONTENT = 204; + const HTTP_RESET_CONTENT = 205; + const HTTP_PARTIAL_CONTENT = 206; + const HTTP_MULTI_STATUS = 207; // RFC4918 + const HTTP_ALREADY_REPORTED = 208; // RFC5842 + const HTTP_IM_USED = 226; // RFC3229 + const HTTP_MULTIPLE_CHOICES = 300; + const HTTP_MOVED_PERMANENTLY = 301; + const HTTP_FOUND = 302; + const HTTP_SEE_OTHER = 303; + const HTTP_NOT_MODIFIED = 304; + const HTTP_USE_PROXY = 305; + const HTTP_RESERVED = 306; + const HTTP_TEMPORARY_REDIRECT = 307; + const HTTP_PERMANENTLY_REDIRECT = 308; // RFC7238 + const HTTP_BAD_REQUEST = 400; + const HTTP_UNAUTHORIZED = 401; + const HTTP_PAYMENT_REQUIRED = 402; + const HTTP_FORBIDDEN = 403; + const HTTP_NOT_FOUND = 404; + const HTTP_METHOD_NOT_ALLOWED = 405; + const HTTP_NOT_ACCEPTABLE = 406; + const HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; + const HTTP_REQUEST_TIMEOUT = 408; + const HTTP_CONFLICT = 409; + const HTTP_GONE = 410; + const HTTP_LENGTH_REQUIRED = 411; + const HTTP_PRECONDITION_FAILED = 412; + const HTTP_REQUEST_ENTITY_TOO_LARGE = 413; + const HTTP_REQUEST_URI_TOO_LONG = 414; + const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; + const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; + const HTTP_EXPECTATION_FAILED = 417; + const HTTP_I_AM_A_TEAPOT = 418; // RFC2324 + const HTTP_MISDIRECTED_REQUEST = 421; // RFC7540 + const HTTP_UNPROCESSABLE_ENTITY = 422; // RFC4918 + const HTTP_LOCKED = 423; // RFC4918 + const HTTP_FAILED_DEPENDENCY = 424; // RFC4918 + const HTTP_TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04 + const HTTP_UPGRADE_REQUIRED = 426; // RFC2817 + const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585 + const HTTP_TOO_MANY_REQUESTS = 429; // RFC6585 + const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 + const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451; + const HTTP_INTERNAL_SERVER_ERROR = 500; + const HTTP_NOT_IMPLEMENTED = 501; + const HTTP_BAD_GATEWAY = 502; + const HTTP_SERVICE_UNAVAILABLE = 503; + const HTTP_GATEWAY_TIMEOUT = 504; + const HTTP_VERSION_NOT_SUPPORTED = 505; const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 - const HTTP_INSUFFICIENT_STORAGE = 507; // RFC4918 - const HTTP_LOOP_DETECTED = 508; // RFC5842 - const HTTP_NOT_EXTENDED = 510; // RFC2774 - const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 + const HTTP_INSUFFICIENT_STORAGE = 507; // RFC4918 + const HTTP_LOOP_DETECTED = 508; // RFC5842 + const HTTP_NOT_EXTENDED = 510; // RFC2774 + const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585 /** * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control