@@ -28,6 +28,9 @@ |
||
| 28 | 28 | return self::$instance; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | + /** |
|
| 32 | + * @param string $message |
|
| 33 | + */ |
|
| 31 | 34 | public static function log($message) |
| 32 | 35 | {
|
| 33 | 36 | self::instance()->console->logError('Gah, this is using Debugger::log()!');
|
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | private function __construct() |
| 19 | 19 | { |
| 20 | 20 | $this->console = new Console(); |
| 21 | - $this->profiler = new PhpQuickProfiler(); |
|
| 22 | - $this->profiler->setConsole($this->console); |
|
| 21 | + $this->profiler = new PhpQuickProfiler(); |
|
| 22 | + $this->profiler->setConsole($this->console); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public static function instance() |
@@ -82,29 +82,29 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | public static function display() |
| 84 | 84 | { |
| 85 | - if ($_COOKIE['debugger'] == 'display' && self::instance()->display) { |
|
| 86 | - $pdo = ''; |
|
| 87 | - global $container; |
|
| 88 | - if (!empty($container) && !empty($container['db_connection_locator'])) { |
|
| 89 | - $pdo = $container['db_connection_locator']->getRead(); |
|
| 90 | - } |
|
| 91 | - if (!empty($pdo)) { |
|
| 92 | - $profiles = $pdo->getProfiler()->getProfiles(); |
|
| 93 | - $profiles = array_filter($profiles, function ($profile) { |
|
| 94 | - return $profile['function'] == 'perform'; |
|
| 95 | - }); |
|
| 96 | - $profiles = array_map(function ($profile) { |
|
| 97 | - return array( |
|
| 98 | - 'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])), |
|
| 99 | - 'parameters' => $profile['bind_values'], |
|
| 100 | - 'time' => $profile['duration'] |
|
| 101 | - ); |
|
| 102 | - }, $profiles); |
|
| 103 | - self::instance()->profiler->setProfiledQueries($profiles); |
|
| 104 | - } |
|
| 105 | - self::instance()->profiler->setDisplay(new Particletree\Pqp\Display()); |
|
| 106 | - self::instance()->profiler->display($pdo); |
|
| 107 | - } |
|
| 85 | + if ($_COOKIE['debugger'] == 'display' && self::instance()->display) { |
|
| 86 | + $pdo = ''; |
|
| 87 | + global $container; |
|
| 88 | + if (!empty($container) && !empty($container['db_connection_locator'])) { |
|
| 89 | + $pdo = $container['db_connection_locator']->getRead(); |
|
| 90 | + } |
|
| 91 | + if (!empty($pdo)) { |
|
| 92 | + $profiles = $pdo->getProfiler()->getProfiles(); |
|
| 93 | + $profiles = array_filter($profiles, function ($profile) { |
|
| 94 | + return $profile['function'] == 'perform'; |
|
| 95 | + }); |
|
| 96 | + $profiles = array_map(function ($profile) { |
|
| 97 | + return array( |
|
| 98 | + 'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])), |
|
| 99 | + 'parameters' => $profile['bind_values'], |
|
| 100 | + 'time' => $profile['duration'] |
|
| 101 | + ); |
|
| 102 | + }, $profiles); |
|
| 103 | + self::instance()->profiler->setProfiledQueries($profiles); |
|
| 104 | + } |
|
| 105 | + self::instance()->profiler->setDisplay(new Particletree\Pqp\Display()); |
|
| 106 | + self::instance()->profiler->display($pdo); |
|
| 107 | + } |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | private static $UNKNOWN_ERROR_FILE = 'Unknown File'; |
| 10 | 10 | private static $UNKNOWN_ERROR_LINE = 'Unknown Line'; |
| 11 | - private static $UNKNOWN_ERROR_CONTEXT = 'Unknown Context'; |
|
| 11 | + private static $UNKNOWN_ERROR_CONTEXT = 'Unknown Context'; |
|
| 12 | 12 | |
| 13 | 13 | private $profiler; |
| 14 | 14 | private $display = true; |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public static function instance() |
| 26 | 26 | { |
| 27 | - if(!isset(self::$instance)) |
|
| 27 | + if (!isset(self::$instance)) |
|
| 28 | 28 | self::$instance = new Debugger(); |
| 29 | 29 | return self::$instance; |
| 30 | 30 | } |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | public static function internal_error($code, $string, $file = null, $line = null, $context = null) |
| 54 | 54 | { |
| 55 | - if($file == null) |
|
| 55 | + if ($file == null) |
|
| 56 | 56 | $file = self::$UNKNOWN_ERROR_FILE; |
| 57 | - if($line == null) |
|
| 57 | + if ($line == null) |
|
| 58 | 58 | $line = self::$UNKNOWN_ERROR_LINE; |
| 59 | - if($context == null) |
|
| 59 | + if ($context == null) |
|
| 60 | 60 | $context = self::$UNKNOWN_ERROR_CONTEXT; |
| 61 | 61 | |
| 62 | 62 | self::instance()->console->logError(new Exception($string), "{$string}... TYPE: {$code}"); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $error = error_get_last(); |
| 70 | 70 | |
| 71 | - if(isset($error)) |
|
| 71 | + if (isset($error)) |
|
| 72 | 72 | self::internal_error($error['type'], $error['message'], $error['file'], $error['line']); |
| 73 | 73 | |
| 74 | 74 | self::display(); |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | if (!empty($pdo)) { |
| 92 | 92 | $profiles = $pdo->getProfiler()->getProfiles(); |
| 93 | - $profiles = array_filter($profiles, function ($profile) { |
|
| 93 | + $profiles = array_filter($profiles, function($profile) { |
|
| 94 | 94 | return $profile['function'] == 'perform'; |
| 95 | 95 | }); |
| 96 | - $profiles = array_map(function ($profile) { |
|
| 96 | + $profiles = array_map(function($profile) { |
|
| 97 | 97 | return array( |
| 98 | 98 | 'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])), |
| 99 | 99 | 'parameters' => $profile['bind_values'], |
@@ -24,8 +24,9 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public static function instance() |
| 26 | 26 | { |
| 27 | - if(!isset(self::$instance)) |
|
| 28 | - self::$instance = new Debugger(); |
|
| 27 | + if(!isset(self::$instance)) {
|
|
| 28 | + self::$instance = new Debugger(); |
|
| 29 | + } |
|
| 29 | 30 | return self::$instance; |
| 30 | 31 | } |
| 31 | 32 | |
@@ -52,12 +53,15 @@ discard block |
||
| 52 | 53 | |
| 53 | 54 | public static function internal_error($code, $string, $file = null, $line = null, $context = null) |
| 54 | 55 | { |
| 55 | - if($file == null) |
|
| 56 | - $file = self::$UNKNOWN_ERROR_FILE; |
|
| 57 | - if($line == null) |
|
| 58 | - $line = self::$UNKNOWN_ERROR_LINE; |
|
| 59 | - if($context == null) |
|
| 60 | - $context = self::$UNKNOWN_ERROR_CONTEXT; |
|
| 56 | + if($file == null) {
|
|
| 57 | + $file = self::$UNKNOWN_ERROR_FILE; |
|
| 58 | + } |
|
| 59 | + if($line == null) {
|
|
| 60 | + $line = self::$UNKNOWN_ERROR_LINE; |
|
| 61 | + } |
|
| 62 | + if($context == null) {
|
|
| 63 | + $context = self::$UNKNOWN_ERROR_CONTEXT; |
|
| 64 | + } |
|
| 61 | 65 | |
| 62 | 66 | self::instance()->console->logError(new Exception($string), "{$string}... TYPE: {$code}"); |
| 63 | 67 | |
@@ -68,8 +72,9 @@ discard block |
||
| 68 | 72 | { |
| 69 | 73 | $error = error_get_last(); |
| 70 | 74 | |
| 71 | - if(isset($error)) |
|
| 72 | - self::internal_error($error['type'], $error['message'], $error['file'], $error['line']); |
|
| 75 | + if(isset($error)) {
|
|
| 76 | + self::internal_error($error['type'], $error['message'], $error['file'], $error['line']); |
|
| 77 | + } |
|
| 73 | 78 | |
| 74 | 79 | self::display(); |
| 75 | 80 | return true; |
@@ -18,6 +18,9 @@ discard block |
||
| 18 | 18 | $this->headers['Bcc'] = "Jacob <{$config->admin_email}>";
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | + /** |
|
| 22 | + * @param string $person |
|
| 23 | + */ |
|
| 21 | 24 | public function setToAddress($email, $person = null) |
| 22 | 25 | {
|
| 23 | 26 | if($person) |
@@ -27,12 +30,18 @@ discard block |
||
| 27 | 30 | return $this; |
| 28 | 31 | } |
| 29 | 32 | |
| 33 | + /** |
|
| 34 | + * @param string $subject |
|
| 35 | + */ |
|
| 30 | 36 | public function setSubject($subject) |
| 31 | 37 | {
|
| 32 | 38 | $this->subject = $subject; |
| 33 | 39 | return $this; |
| 34 | 40 | } |
| 35 | 41 | |
| 42 | + /** |
|
| 43 | + * @param string $message |
|
| 44 | + */ |
|
| 36 | 45 | public function setMessage($message) |
| 37 | 46 | {
|
| 38 | 47 | $this->message = $message; |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | public function __construct() |
| 14 | 14 | { |
| 15 | - global $config; |
|
| 15 | + global $config; |
|
| 16 | 16 | $this->headers['From'] = self::$FROM; |
| 17 | 17 | $this->headers['Reply-To'] = "Jacob <{$config->admin_email}>"; |
| 18 | 18 | $this->headers['Bcc'] = "Jacob <{$config->admin_email}>"; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function setToAddress($email, $person = null) |
| 22 | 22 | { |
| 23 | - if($person) |
|
| 23 | + if ($person) |
|
| 24 | 24 | $this->to[] = "{$person} <{$email}>"; |
| 25 | 25 | else |
| 26 | 26 | $this->to[] = "{$email}"; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | public function send() |
| 43 | 43 | { |
| 44 | - if(!Loader::isLive()) |
|
| 44 | + if (!Loader::isLive()) |
|
| 45 | 45 | { |
| 46 | 46 | Debugger::logMessage("Email Failed:\n\n{$this->message}"); |
| 47 | 47 | return; |
@@ -51,14 +51,14 @@ discard block |
||
| 51 | 51 | $subject = $this->subject; |
| 52 | 52 | $message = $this->message; |
| 53 | 53 | |
| 54 | - if(empty($to) || empty($subject) || empty($message)) |
|
| 54 | + if (empty($to) || empty($subject) || empty($message)) |
|
| 55 | 55 | { |
| 56 | 56 | Debugger::logMessage("Attempted to send an email without all of the required fields."); |
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $header = ''; |
| 61 | - foreach($this->headers as $key => $value) |
|
| 61 | + foreach ($this->headers as $key => $value) |
|
| 62 | 62 | { |
| 63 | 63 | $header .= "{$key}: {$value}\r\n"; |
| 64 | 64 | } |
@@ -20,10 +20,11 @@ |
||
| 20 | 20 | |
| 21 | 21 | public function setToAddress($email, $person = null) |
| 22 | 22 | { |
| 23 | - if($person) |
|
| 24 | - $this->to[] = "{$person} <{$email}>"; |
|
| 25 | - else |
|
| 26 | - $this->to[] = "{$email}"; |
|
| 23 | + if($person) {
|
|
| 24 | + $this->to[] = "{$person} <{$email}>";
|
|
| 25 | + } else {
|
|
| 26 | + $this->to[] = "{$email}";
|
|
| 27 | + } |
|
| 27 | 28 | return $this; |
| 28 | 29 | } |
| 29 | 30 | |
@@ -34,6 +34,9 @@ |
||
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | + /** |
|
| 38 | + * @param string $key |
|
| 39 | + */ |
|
| 37 | 40 | static function getGet($key = null) |
| 38 | 41 | {
|
| 39 | 42 | if($key) |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | static function getServer($key = null) |
| 20 | 20 | { |
| 21 | - if($key) |
|
| 21 | + if ($key) |
|
| 22 | 22 | { |
| 23 | - if(isset(self::$server[$key])) |
|
| 23 | + if (isset(self::$server[$key])) |
|
| 24 | 24 | return self::$server[$key]; |
| 25 | 25 | return false; |
| 26 | 26 | } |
@@ -29,16 +29,16 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | static function isAjax() |
| 31 | 31 | { |
| 32 | - if(self::getServer(self::$AJAX_REQUEST)) |
|
| 32 | + if (self::getServer(self::$AJAX_REQUEST)) |
|
| 33 | 33 | return true; |
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | static function getGet($key = null) |
| 38 | 38 | { |
| 39 | - if($key) |
|
| 39 | + if ($key) |
|
| 40 | 40 | { |
| 41 | - if(isset(self::$get[$key])) |
|
| 41 | + if (isset(self::$get[$key])) |
|
| 42 | 42 | return self::$get[$key]; |
| 43 | 43 | return false; |
| 44 | 44 | } |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | static function getPost($key = null) |
| 49 | 49 | { |
| 50 | - if($key) |
|
| 50 | + if ($key) |
|
| 51 | 51 | { |
| 52 | - if(isset(self::$post[$key])) |
|
| 52 | + if (isset(self::$post[$key])) |
|
| 53 | 53 | return self::$post[$key]; |
| 54 | 54 | return false; |
| 55 | 55 | } |
@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | if($key) |
| 22 | 22 | { |
| 23 | - if(isset(self::$server[$key])) |
|
| 24 | - return self::$server[$key]; |
|
| 23 | + if(isset(self::$server[$key])) {
|
|
| 24 | + return self::$server[$key]; |
|
| 25 | + } |
|
| 25 | 26 | return false; |
| 26 | 27 | } |
| 27 | 28 | return self::$server; |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | |
| 30 | 31 | static function isAjax() |
| 31 | 32 | { |
| 32 | - if(self::getServer(self::$AJAX_REQUEST)) |
|
| 33 | - return true; |
|
| 33 | + if(self::getServer(self::$AJAX_REQUEST)) {
|
|
| 34 | + return true; |
|
| 35 | + } |
|
| 34 | 36 | return false; |
| 35 | 37 | } |
| 36 | 38 | |
@@ -38,8 +40,9 @@ discard block |
||
| 38 | 40 | { |
| 39 | 41 | if($key) |
| 40 | 42 | { |
| 41 | - if(isset(self::$get[$key])) |
|
| 42 | - return self::$get[$key]; |
|
| 43 | + if(isset(self::$get[$key])) {
|
|
| 44 | + return self::$get[$key]; |
|
| 45 | + } |
|
| 43 | 46 | return false; |
| 44 | 47 | } |
| 45 | 48 | return self::$get; |
@@ -49,8 +52,9 @@ discard block |
||
| 49 | 52 | { |
| 50 | 53 | if($key) |
| 51 | 54 | { |
| 52 | - if(isset(self::$post[$key])) |
|
| 53 | - return self::$post[$key]; |
|
| 55 | + if(isset(self::$post[$key])) {
|
|
| 56 | + return self::$post[$key]; |
|
| 57 | + } |
|
| 54 | 58 | return false; |
| 55 | 59 | } |
| 56 | 60 | return self::$post; |
@@ -72,6 +72,11 @@ |
||
| 72 | 72 | return $matches[0] == $string; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | + /** |
|
| 76 | + * @param string $type |
|
| 77 | + * @param string $key |
|
| 78 | + * @param string $validation |
|
| 79 | + */ |
|
| 75 | 80 | public static function checkRequest($type, $key, $validation, $strict = false) |
| 76 | 81 | {
|
| 77 | 82 | switch($type) |
@@ -11,39 +11,39 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | public static function isBoolean($value, $strict = false) |
| 13 | 13 | { |
| 14 | - if($strict && ($value === true || $value === false)) |
|
| 14 | + if ($strict && ($value === true || $value === false)) |
|
| 15 | 15 | return true; |
| 16 | - if(!$strict && ((bool) $value === true || (bool) $value === false)) |
|
| 16 | + if (!$strict && ((bool) $value === true || (bool) $value === false)) |
|
| 17 | 17 | return true; |
| 18 | 18 | return false; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static function isDate($value) |
| 22 | 22 | { |
| 23 | - if(strtotime($value) !== -1) |
|
| 23 | + if (strtotime($value) !== -1) |
|
| 24 | 24 | return true; |
| 25 | - if(date('y', $value) !== false) |
|
| 25 | + if (date('y', $value) !== false) |
|
| 26 | 26 | return true; |
| 27 | 27 | return false; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public static function isInteger($value, $strict = false) |
| 31 | 31 | { |
| 32 | - if($strict) |
|
| 32 | + if ($strict) |
|
| 33 | 33 | return is_int($value); |
| 34 | 34 | return (int) $value == $value; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public static function isIP($value) |
| 38 | 38 | { |
| 39 | - if(self::isInteger(ip2long($value))) |
|
| 39 | + if (self::isInteger(ip2long($value))) |
|
| 40 | 40 | return true; |
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public static function isString($value, $strict = false) |
| 45 | 45 | { |
| 46 | - if($strict) |
|
| 46 | + if ($strict) |
|
| 47 | 47 | return is_string($value); |
| 48 | 48 | return (string) $value == $value; |
| 49 | 49 | } |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | private static function check_value($pattern, $string) |
| 68 | 68 | { |
| 69 | 69 | preg_match($pattern, $string, $matches); |
| 70 | - if(empty($matches)) |
|
| 70 | + if (empty($matches)) |
|
| 71 | 71 | return false; |
| 72 | 72 | return $matches[0] == $string; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public static function checkRequest($type, $key, $validation, $strict = false) |
| 76 | 76 | { |
| 77 | - switch($type) |
|
| 77 | + switch ($type) |
|
| 78 | 78 | { |
| 79 | 79 | case 'server': |
| 80 | 80 | $value = Request::getServer($key); |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | break; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if($value == false) |
|
| 87 | + if ($value == false) |
|
| 88 | 88 | return false; |
| 89 | 89 | |
| 90 | - switch($validation) |
|
| 90 | + switch ($validation) |
|
| 91 | 91 | { |
| 92 | 92 | case 'boolean': |
| 93 | 93 | return self::isBoolean($value, $strict); |
@@ -11,40 +11,47 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | public static function isBoolean($value, $strict = false) |
| 13 | 13 | { |
| 14 | - if($strict && ($value === true || $value === false)) |
|
| 15 | - return true; |
|
| 16 | - if(!$strict && ((bool) $value === true || (bool) $value === false)) |
|
| 17 | - return true; |
|
| 14 | + if($strict && ($value === true || $value === false)) {
|
|
| 15 | + return true; |
|
| 16 | + } |
|
| 17 | + if(!$strict && ((bool) $value === true || (bool) $value === false)) {
|
|
| 18 | + return true; |
|
| 19 | + } |
|
| 18 | 20 | return false; |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | public static function isDate($value) |
| 22 | 24 | { |
| 23 | - if(strtotime($value) !== -1) |
|
| 24 | - return true; |
|
| 25 | - if(date('y', $value) !== false) |
|
| 26 | - return true; |
|
| 25 | + if(strtotime($value) !== -1) {
|
|
| 26 | + return true; |
|
| 27 | + } |
|
| 28 | + if(date('y', $value) !== false) {
|
|
| 29 | + return true; |
|
| 30 | + } |
|
| 27 | 31 | return false; |
| 28 | 32 | } |
| 29 | 33 | |
| 30 | 34 | public static function isInteger($value, $strict = false) |
| 31 | 35 | { |
| 32 | - if($strict) |
|
| 33 | - return is_int($value); |
|
| 36 | + if($strict) {
|
|
| 37 | + return is_int($value); |
|
| 38 | + } |
|
| 34 | 39 | return (int) $value == $value; |
| 35 | 40 | } |
| 36 | 41 | |
| 37 | 42 | public static function isIP($value) |
| 38 | 43 | { |
| 39 | - if(self::isInteger(ip2long($value))) |
|
| 40 | - return true; |
|
| 44 | + if(self::isInteger(ip2long($value))) {
|
|
| 45 | + return true; |
|
| 46 | + } |
|
| 41 | 47 | return false; |
| 42 | 48 | } |
| 43 | 49 | |
| 44 | 50 | public static function isString($value, $strict = false) |
| 45 | 51 | { |
| 46 | - if($strict) |
|
| 47 | - return is_string($value); |
|
| 52 | + if($strict) {
|
|
| 53 | + return is_string($value); |
|
| 54 | + } |
|
| 48 | 55 | return (string) $value == $value; |
| 49 | 56 | } |
| 50 | 57 | |
@@ -67,8 +74,9 @@ discard block |
||
| 67 | 74 | private static function check_value($pattern, $string) |
| 68 | 75 | { |
| 69 | 76 | preg_match($pattern, $string, $matches); |
| 70 | - if(empty($matches)) |
|
| 71 | - return false; |
|
| 77 | + if(empty($matches)) {
|
|
| 78 | + return false; |
|
| 79 | + } |
|
| 72 | 80 | return $matches[0] == $string; |
| 73 | 81 | } |
| 74 | 82 | |
@@ -84,8 +92,9 @@ discard block |
||
| 84 | 92 | break; |
| 85 | 93 | } |
| 86 | 94 | |
| 87 | - if($value == false) |
|
| 88 | - return false; |
|
| 95 | + if($value == false) {
|
|
| 96 | + return false; |
|
| 97 | + } |
|
| 89 | 98 | |
| 90 | 99 | switch($validation) |
| 91 | 100 | { |
@@ -239,6 +239,9 @@ |
||
| 239 | 239 | return $text; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | + /** |
|
| 243 | + * @param string $type |
|
| 244 | + */ |
|
| 242 | 245 | private function get_replace_text($entity_type, $entity, $type) |
| 243 | 246 | {
|
| 244 | 247 | switch($entity_type) |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | public function __construct() |
| 14 | 14 | { |
| 15 | 15 | $extendedPdo = $this->newExtendedPdo(); |
| 16 | - $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 16 | + $this->connections = new ConnectionLocator(function() use ($extendedPdo) { |
|
| 17 | 17 | return $extendedPdo; |
| 18 | 18 | }); |
| 19 | 19 | } |
@@ -7,21 +7,21 @@ discard block |
||
| 7 | 7 | class MysqlPostRepositoryTest extends PHPUnit_Framework_TestCase |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - protected $connections; |
|
| 11 | - |
|
| 12 | - public function __construct() |
|
| 13 | - { |
|
| 14 | - $extendedPdo = $this->newExtendedPdo(); |
|
| 15 | - $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 16 | - return $extendedPdo; |
|
| 17 | - }); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - protected function newExtendedPdo() |
|
| 21 | - { |
|
| 22 | - $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 23 | - $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
| 24 | - $extendedPdo->exec(" |
|
| 10 | + protected $connections; |
|
| 11 | + |
|
| 12 | + public function __construct() |
|
| 13 | + { |
|
| 14 | + $extendedPdo = $this->newExtendedPdo(); |
|
| 15 | + $this->connections = new ConnectionLocator(function () use ($extendedPdo) { |
|
| 16 | + return $extendedPdo; |
|
| 17 | + }); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + protected function newExtendedPdo() |
|
| 21 | + { |
|
| 22 | + $extendedPdo = new ExtendedPdo('sqlite::memory:'); |
|
| 23 | + $extendedPdo->exec('ATTACH DATABASE `jpemeric_blog.db` AS `jpemeric_blog`'); |
|
| 24 | + $extendedPdo->exec(" |
|
| 25 | 25 | CREATE TABLE IF NOT EXISTS `jpemeric_blog`.`post` ( |
| 26 | 26 | `id` integer PRIMARY KEY AUTOINCREMENT, |
| 27 | 27 | `title` varchar(60) NOT NULL, |
@@ -31,88 +31,88 @@ discard block |
||
| 31 | 31 | `body` text NOT NULL, |
| 32 | 32 | `display` integer NOT NULL |
| 33 | 33 | )" |
| 34 | - ); |
|
| 35 | - return $extendedPdo; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function newMysqlPostRepository() |
|
| 39 | - { |
|
| 40 | - return new MysqlPostRepository($this->connections); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function testConstructSetsConnections() |
|
| 44 | - { |
|
| 45 | - $this->assertAttributeEquals( |
|
| 46 | - $this->connections, |
|
| 47 | - 'connections', |
|
| 48 | - $this->newMysqlPostRepository() |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function testFindPostByPath() |
|
| 53 | - { |
|
| 54 | - $test_active_post = array( |
|
| 55 | - 'title' => 'test findByPath active', |
|
| 56 | - 'path' => 'test-findbypath-active', |
|
| 57 | - 'category' => 'test-category', |
|
| 58 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 59 | - 'body' => 'test content', |
|
| 60 | - 'display' => 1 |
|
| 61 | - ); |
|
| 62 | - |
|
| 63 | - $this->connections->getDefault()->perform(" |
|
| 34 | + ); |
|
| 35 | + return $extendedPdo; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function newMysqlPostRepository() |
|
| 39 | + { |
|
| 40 | + return new MysqlPostRepository($this->connections); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function testConstructSetsConnections() |
|
| 44 | + { |
|
| 45 | + $this->assertAttributeEquals( |
|
| 46 | + $this->connections, |
|
| 47 | + 'connections', |
|
| 48 | + $this->newMysqlPostRepository() |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function testFindPostByPath() |
|
| 53 | + { |
|
| 54 | + $test_active_post = array( |
|
| 55 | + 'title' => 'test findByPath active', |
|
| 56 | + 'path' => 'test-findbypath-active', |
|
| 57 | + 'category' => 'test-category', |
|
| 58 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 59 | + 'body' => 'test content', |
|
| 60 | + 'display' => 1 |
|
| 61 | + ); |
|
| 62 | + |
|
| 63 | + $this->connections->getDefault()->perform(" |
|
| 64 | 64 | INSERT INTO jpemeric_blog.post |
| 65 | 65 | (title, path, category, date, body, display) |
| 66 | 66 | VALUES |
| 67 | 67 | (:title, :path, :category, :date, :body, :display)", |
| 68 | - $test_active_post); |
|
| 69 | - |
|
| 70 | - $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 71 | - $test_active_post['category'], |
|
| 72 | - $test_active_post['path'] |
|
| 73 | - ); |
|
| 74 | - $this->assertSame($test_active_post['title'], $active_post['title']); |
|
| 75 | - |
|
| 76 | - $test_inactive_post = array( |
|
| 77 | - 'title' => 'test findByPath inactive', |
|
| 78 | - 'path' => 'test-findbypath-inactive', |
|
| 79 | - 'category' => 'test-category', |
|
| 80 | - 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 81 | - 'body' => 'test content', |
|
| 82 | - 'display' => 0 |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - $this->connections->getDefault()->perform(" |
|
| 68 | + $test_active_post); |
|
| 69 | + |
|
| 70 | + $active_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 71 | + $test_active_post['category'], |
|
| 72 | + $test_active_post['path'] |
|
| 73 | + ); |
|
| 74 | + $this->assertSame($test_active_post['title'], $active_post['title']); |
|
| 75 | + |
|
| 76 | + $test_inactive_post = array( |
|
| 77 | + 'title' => 'test findByPath inactive', |
|
| 78 | + 'path' => 'test-findbypath-inactive', |
|
| 79 | + 'category' => 'test-category', |
|
| 80 | + 'date' => (new DateTime())->format('Y-m-d H:i:s'), |
|
| 81 | + 'body' => 'test content', |
|
| 82 | + 'display' => 0 |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + $this->connections->getDefault()->perform(" |
|
| 86 | 86 | INSERT INTO jpemeric_blog.post |
| 87 | 87 | (title, path, category, date, body, display) |
| 88 | 88 | VALUES |
| 89 | 89 | (:title, :path, :category, :date, :body, :display)", |
| 90 | - $test_inactive_post); |
|
| 91 | - |
|
| 92 | - $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 93 | - $test_inactive_post['category'], |
|
| 94 | - $test_inactive_post['path'] |
|
| 95 | - ); |
|
| 96 | - $this->assertFalse($inactive_post); |
|
| 97 | - |
|
| 98 | - $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 99 | - 'test-category', |
|
| 100 | - 'test-findbypath-nonexistant' |
|
| 101 | - ); |
|
| 102 | - $this->assertFalse($nonexistant_post); |
|
| 90 | + $test_inactive_post); |
|
| 91 | + |
|
| 92 | + $inactive_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 93 | + $test_inactive_post['category'], |
|
| 94 | + $test_inactive_post['path'] |
|
| 95 | + ); |
|
| 96 | + $this->assertFalse($inactive_post); |
|
| 97 | + |
|
| 98 | + $nonexistant_post = $this->newMysqlPostRepository()->findPostByPath( |
|
| 99 | + 'test-category', |
|
| 100 | + 'test-findbypath-nonexistant' |
|
| 101 | + ); |
|
| 102 | + $this->assertFalse($nonexistant_post); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - public function testIsInstanceOfPostRepository() |
|
| 106 | - { |
|
| 107 | - $this->assertInstanceOf( |
|
| 108 | - 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
| 109 | - $this->newMysqlPostRepository() |
|
| 110 | - ); |
|
| 111 | - } |
|
| 105 | + public function testIsInstanceOfPostRepository() |
|
| 106 | + { |
|
| 107 | + $this->assertInstanceOf( |
|
| 108 | + 'Jacobemerick\Web\Domain\Blog\Post\PostRepositoryInterface', |
|
| 109 | + $this->newMysqlPostRepository() |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - public static function tearDownAfterClass() |
|
| 114 | - { |
|
| 113 | + public static function tearDownAfterClass() |
|
| 114 | + { |
|
| 115 | 115 | // $this->connections->getDefault()->disconnect(); |
| 116 | - unlink('jpemeric_blog.db'); |
|
| 117 | - } |
|
| 116 | + unlink('jpemeric_blog.db'); |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -36,6 +36,10 @@ discard block |
||
| 36 | 36 | $this->replace_element_patterns(); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + /** |
|
| 40 | + * @param string $pattern |
|
| 41 | + * @param string $replace |
|
| 42 | + */ |
|
| 39 | 43 | private function process_element($pattern, $replace) |
| 40 | 44 | {
|
| 41 | 45 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
@@ -75,6 +79,10 @@ discard block |
||
| 75 | 79 | $this->content = strip_tags($this->content); |
| 76 | 80 | } |
| 77 | 81 | |
| 82 | + /** |
|
| 83 | + * @param string $pattern |
|
| 84 | + * @param string $replace |
|
| 85 | + */ |
|
| 78 | 86 | private function link_unlinked_urls($pattern, $replace) |
| 79 | 87 | {
|
| 80 | 88 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
| 42 | 42 | |
| 43 | - if($match_count < 1) |
|
| 43 | + if ($match_count < 1) |
|
| 44 | 44 | return; |
| 45 | 45 | |
| 46 | - foreach($matches as $match) |
|
| 46 | + foreach ($matches as $match) |
|
| 47 | 47 | { |
| 48 | 48 | $full_match = array_shift($match); |
| 49 | 49 | $placeholder = $this->create_placeholder($full_match); |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | { |
| 80 | 80 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
| 81 | 81 | |
| 82 | - if($match_count < 1) |
|
| 82 | + if ($match_count < 1) |
|
| 83 | 83 | return; |
| 84 | 84 | |
| 85 | - foreach($matches as $match) |
|
| 85 | + foreach ($matches as $match) |
|
| 86 | 86 | { |
| 87 | 87 | $full_match = array_shift($match); |
| 88 | 88 | $full_match_pattern = $this->create_full_match_pattern($full_match); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | private function replace_element_patterns() |
| 101 | 101 | { |
| 102 | - foreach($this->replacement_array as $key => $replace) |
|
| 102 | + foreach ($this->replacement_array as $key => $replace) |
|
| 103 | 103 | { |
| 104 | 104 | $this->content = str_replace($key, $replace, $this->content); |
| 105 | 105 | } |
@@ -40,8 +40,9 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
| 42 | 42 | |
| 43 | - if($match_count < 1) |
|
| 44 | - return; |
|
| 43 | + if($match_count < 1) {
|
|
| 44 | + return; |
|
| 45 | + } |
|
| 45 | 46 | |
| 46 | 47 | foreach($matches as $match) |
| 47 | 48 | { |
@@ -79,8 +80,9 @@ discard block |
||
| 79 | 80 | { |
| 80 | 81 | $match_count = preg_match_all($pattern, $this->content, $matches, PREG_SET_ORDER); |
| 81 | 82 | |
| 82 | - if($match_count < 1) |
|
| 83 | - return; |
|
| 83 | + if($match_count < 1) {
|
|
| 84 | + return; |
|
| 85 | + } |
|
| 84 | 86 | |
| 85 | 87 | foreach($matches as $match) |
| 86 | 88 | { |
@@ -23,6 +23,9 @@ |
||
| 23 | 23 | return; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | + /** |
|
| 27 | + * @param boolean $is_absolute |
|
| 28 | + */ |
|
| 26 | 29 | private function get_link($string, $is_absolute, $anchor = '') |
| 27 | 30 | {
|
| 28 | 31 | list($type, $uri) = explode('/', $string, 2);
|
@@ -72,38 +72,38 @@ |
||
| 72 | 72 | |
| 73 | 73 | break; |
| 74 | 74 | case 'falls' : |
| 75 | - $pieces = explode('/', $uri); |
|
| 76 | - if (count($pieces) == 1) { |
|
| 77 | - Loader::load('collector', 'waterfall/WatercourseCollector'); |
|
| 78 | - list ($watercourse_alias) = $pieces; |
|
| 79 | - $watercourse = WatercourseCollector::getByAlias($watercourse_alias); |
|
| 75 | + $pieces = explode('/', $uri); |
|
| 76 | + if (count($pieces) == 1) { |
|
| 77 | + Loader::load('collector', 'waterfall/WatercourseCollector'); |
|
| 78 | + list ($watercourse_alias) = $pieces; |
|
| 79 | + $watercourse = WatercourseCollector::getByAlias($watercourse_alias); |
|
| 80 | 80 | |
| 81 | - if ($watercourse == null) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 81 | + if ($watercourse == null) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
|
| 86 | - $link .= "{$watercourse->alias}/"; |
|
| 85 | + $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
|
| 86 | + $link .= "{$watercourse->alias}/"; |
|
| 87 | 87 | |
| 88 | - if ($anchor == '') { |
|
| 89 | - $anchor = $watercourse->name; |
|
| 90 | - } |
|
| 91 | - } else if (count($pieces) == 2) { |
|
| 92 | - Loader::load('collector', 'waterfall/WaterfallCollector'); |
|
| 93 | - list ($watercourse_alias, $waterfall_alias) = $pieces; |
|
| 94 | - $waterfall = WaterfallCollector::getByAlias($watercourse_alias, $waterfall_alias); |
|
| 88 | + if ($anchor == '') { |
|
| 89 | + $anchor = $watercourse->name; |
|
| 90 | + } |
|
| 91 | + } else if (count($pieces) == 2) { |
|
| 92 | + Loader::load('collector', 'waterfall/WaterfallCollector'); |
|
| 93 | + list ($watercourse_alias, $waterfall_alias) = $pieces; |
|
| 94 | + $waterfall = WaterfallCollector::getByAlias($watercourse_alias, $waterfall_alias); |
|
| 95 | 95 | |
| 96 | - if ($waterfall == null) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 96 | + if ($waterfall == null) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
|
| 101 | - $link .= "{$waterfall->watercourse_alias}/{$waterfall->alias}/"; |
|
| 100 | + $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
|
| 101 | + $link .= "{$waterfall->watercourse_alias}/{$waterfall->alias}/"; |
|
| 102 | 102 | |
| 103 | - if ($anchor == '') { |
|
| 104 | - $anchor = $waterfall->name; |
|
| 105 | - } |
|
| 106 | - } |
|
| 103 | + if ($anchor == '') { |
|
| 104 | + $anchor = $waterfall->name; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | break; |
| 108 | 108 | default : |
| 109 | 109 | break; |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | protected function execute($is_absolute = true) |
| 13 | 13 | { |
| 14 | 14 | preg_match_all(self::$LINK_PLACEHOLDER_MATCH, $this->content, $matches); |
| 15 | - foreach($matches[1] as $key => $match) |
|
| 15 | + foreach ($matches[1] as $key => $match) |
|
| 16 | 16 | { |
| 17 | - if(isset($matches[3][$key])) |
|
| 17 | + if (isset($matches[3][$key])) |
|
| 18 | 18 | $link_content = $this->get_link($match, $is_absolute, $matches[3][$key]); |
| 19 | 19 | else |
| 20 | 20 | $link_content = $this->get_link($match, $is_absolute); |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | $link = ''; |
| 31 | 31 | |
| 32 | - switch($type) |
|
| 32 | + switch ($type) |
|
| 33 | 33 | { |
| 34 | 34 | case 'blog' : |
| 35 | 35 | Loader::load('collector', 'blog/PostCollector'); |
| 36 | 36 | $post = PostCollector::getPostByURI($uri); |
| 37 | 37 | |
| 38 | - if($post === NULL) |
|
| 38 | + if ($post === NULL) |
|
| 39 | 39 | return; |
| 40 | 40 | |
| 41 | 41 | $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
| 42 | 42 | $link .= "{$post->category}/{$post->path}/"; |
| 43 | 43 | |
| 44 | - if($anchor == '') |
|
| 44 | + if ($anchor == '') |
|
| 45 | 45 | $anchor = $post->title; |
| 46 | 46 | |
| 47 | 47 | break; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
| 50 | 50 | $link .= "tag/{$uri}/"; |
| 51 | 51 | |
| 52 | - if($anchor == '') |
|
| 52 | + if ($anchor == '') |
|
| 53 | 53 | { |
| 54 | 54 | $anchor = $uri; |
| 55 | 55 | $anchor = str_replace('-', ' ', $anchor); |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | Loader::load('collector', 'waterfall/LogCollector'); |
| 62 | 62 | $log = LogCollector::getByAlias($uri); |
| 63 | 63 | |
| 64 | - if($log === NULL) |
|
| 64 | + if ($log === NULL) |
|
| 65 | 65 | return; |
| 66 | 66 | |
| 67 | 67 | $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
| 68 | 68 | $link .= "journal/{$log->alias}/"; |
| 69 | 69 | |
| 70 | - if($anchor == '') |
|
| 70 | + if ($anchor == '') |
|
| 71 | 71 | $anchor = $log->title; |
| 72 | 72 | |
| 73 | 73 | break; |
@@ -14,10 +14,11 @@ discard block |
||
| 14 | 14 | preg_match_all(self::$LINK_PLACEHOLDER_MATCH, $this->content, $matches); |
| 15 | 15 | foreach($matches[1] as $key => $match) |
| 16 | 16 | { |
| 17 | - if(isset($matches[3][$key])) |
|
| 18 | - $link_content = $this->get_link($match, $is_absolute, $matches[3][$key]); |
|
| 19 | - else |
|
| 20 | - $link_content = $this->get_link($match, $is_absolute); |
|
| 17 | + if(isset($matches[3][$key])) {
|
|
| 18 | + $link_content = $this->get_link($match, $is_absolute, $matches[3][$key]); |
|
| 19 | + } else {
|
|
| 20 | + $link_content = $this->get_link($match, $is_absolute); |
|
| 21 | + } |
|
| 21 | 22 | $this->content = str_replace($matches[0][$key], $link_content, $this->content); |
| 22 | 23 | } |
| 23 | 24 | return; |
@@ -35,14 +36,16 @@ discard block |
||
| 35 | 36 | Loader::load('collector', 'blog/PostCollector'); |
| 36 | 37 | $post = PostCollector::getPostByURI($uri); |
| 37 | 38 | |
| 38 | - if($post === NULL) |
|
| 39 | - return; |
|
| 39 | + if($post === NULL) {
|
|
| 40 | + return; |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | $link .= ($is_absolute) ? Loader::getRootURL('blog') : '/'; |
| 42 | 44 | $link .= "{$post->category}/{$post->path}/"; |
| 43 | 45 | |
| 44 | - if($anchor == '') |
|
| 45 | - $anchor = $post->title; |
|
| 46 | + if($anchor == '') {
|
|
| 47 | + $anchor = $post->title; |
|
| 48 | + } |
|
| 46 | 49 | |
| 47 | 50 | break; |
| 48 | 51 | case 'blog-tag' : |
@@ -61,14 +64,16 @@ discard block |
||
| 61 | 64 | Loader::load('collector', 'waterfall/LogCollector'); |
| 62 | 65 | $log = LogCollector::getByAlias($uri); |
| 63 | 66 | |
| 64 | - if($log === NULL) |
|
| 65 | - return; |
|
| 67 | + if($log === NULL) {
|
|
| 68 | + return; |
|
| 69 | + } |
|
| 66 | 70 | |
| 67 | 71 | $link .= ($is_absolute) ? Loader::getRootURL('waterfalls') : '/'; |
| 68 | 72 | $link .= "journal/{$log->alias}/"; |
| 69 | 73 | |
| 70 | - if($anchor == '') |
|
| 71 | - $anchor = $log->title; |
|
| 74 | + if($anchor == '') {
|
|
| 75 | + $anchor = $log->title; |
|
| 76 | + } |
|
| 72 | 77 | |
| 73 | 78 | break; |
| 74 | 79 | case 'falls' : |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | protected $connections; |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | - * @param Aura\Sql\ConnectionLocator $connections |
|
| 14 | + * @param ConnectionLocator $connections |
|
| 15 | 15 | */ |
| 16 | 16 | public function __construct(ConnectionLocator $connections) |
| 17 | 17 | { |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param string $category |
| 23 | 23 | * @param string $path |
| 24 | 24 | * |
| 25 | - * @return array|false |
|
| 25 | + * @return boolean |
|
| 26 | 26 | */ |
| 27 | 27 | public function findByPath($category, $path) |
| 28 | 28 | { |
@@ -7,165 +7,165 @@ discard block |
||
| 7 | 7 | class MysqlPostRepository implements PostRepository |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** @var Aura\Sql\ConnectionLocator */ |
|
| 11 | - protected $connections; |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * @param Aura\Sql\ConnectionLocator $connections |
|
| 15 | - */ |
|
| 16 | - public function __construct(ConnectionLocator $connections) |
|
| 17 | - { |
|
| 18 | - $this->connections = $connections; |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param string $category |
|
| 23 | - * @param string $path |
|
| 24 | - * |
|
| 25 | - * @return array|false |
|
| 26 | - */ |
|
| 27 | - public function findPostByPath($category, $path) |
|
| 28 | - { |
|
| 29 | - $query = " |
|
| 10 | + /** @var Aura\Sql\ConnectionLocator */ |
|
| 11 | + protected $connections; |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * @param Aura\Sql\ConnectionLocator $connections |
|
| 15 | + */ |
|
| 16 | + public function __construct(ConnectionLocator $connections) |
|
| 17 | + { |
|
| 18 | + $this->connections = $connections; |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param string $category |
|
| 23 | + * @param string $path |
|
| 24 | + * |
|
| 25 | + * @return array|false |
|
| 26 | + */ |
|
| 27 | + public function findPostByPath($category, $path) |
|
| 28 | + { |
|
| 29 | + $query = " |
|
| 30 | 30 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 31 | 31 | FROM `jpemeric_blog`.`post` |
| 32 | 32 | WHERE `path` = :path AND `category` = :category AND `display` = :is_active |
| 33 | 33 | LIMIT 1"; |
| 34 | - $bindings = [ |
|
| 35 | - 'path' => $path, |
|
| 36 | - 'category' => $category, |
|
| 37 | - 'is_active' => 1, |
|
| 38 | - ]; |
|
| 39 | - |
|
| 40 | - return $this |
|
| 41 | - ->connections |
|
| 42 | - ->getRead() |
|
| 43 | - ->fetchOne($query, $bindings); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function getActivePosts($limit = null, $offset = 0) |
|
| 47 | - { |
|
| 48 | - $query = " |
|
| 34 | + $bindings = [ |
|
| 35 | + 'path' => $path, |
|
| 36 | + 'category' => $category, |
|
| 37 | + 'is_active' => 1, |
|
| 38 | + ]; |
|
| 39 | + |
|
| 40 | + return $this |
|
| 41 | + ->connections |
|
| 42 | + ->getRead() |
|
| 43 | + ->fetchOne($query, $bindings); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function getActivePosts($limit = null, $offset = 0) |
|
| 47 | + { |
|
| 48 | + $query = " |
|
| 49 | 49 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 50 | 50 | FROM `jpemeric_blog`.`post` |
| 51 | 51 | WHERE `display` = :is_active |
| 52 | 52 | ORDER BY `date` DESC"; |
| 53 | - if ($limit != null) { |
|
| 54 | - $query .= " |
|
| 53 | + if ($limit != null) { |
|
| 54 | + $query .= " |
|
| 55 | 55 | LIMIT {$offset}, {$limit}"; |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $bindings = [ |
|
| 59 | - 'is_active' => 1, |
|
| 60 | - ]; |
|
| 58 | + $bindings = [ |
|
| 59 | + 'is_active' => 1, |
|
| 60 | + ]; |
|
| 61 | 61 | |
| 62 | - return $this |
|
| 63 | - ->connections |
|
| 64 | - ->getRead() |
|
| 65 | - ->fetchAll($query, $bindings); |
|
| 66 | - } |
|
| 62 | + return $this |
|
| 63 | + ->connections |
|
| 64 | + ->getRead() |
|
| 65 | + ->fetchAll($query, $bindings); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function getActivePostsCount() |
|
| 69 | - { |
|
| 70 | - $query = " |
|
| 68 | + public function getActivePostsCount() |
|
| 69 | + { |
|
| 70 | + $query = " |
|
| 71 | 71 | SELECT COUNT(1) AS `count` |
| 72 | 72 | FROM `jpemeric_blog`.`post` |
| 73 | 73 | WHERE `display` = :is_active"; |
| 74 | - $bindings = [ |
|
| 75 | - 'is_active' => 1, |
|
| 76 | - ]; |
|
| 77 | - |
|
| 78 | - return $this |
|
| 79 | - ->connections |
|
| 80 | - ->getRead() |
|
| 81 | - ->fetchValue($query, $bindings); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function getActivePostsByTag($tag, $limit = null, $offset = 0) |
|
| 85 | - { |
|
| 86 | - $query = " |
|
| 74 | + $bindings = [ |
|
| 75 | + 'is_active' => 1, |
|
| 76 | + ]; |
|
| 77 | + |
|
| 78 | + return $this |
|
| 79 | + ->connections |
|
| 80 | + ->getRead() |
|
| 81 | + ->fetchValue($query, $bindings); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function getActivePostsByTag($tag, $limit = null, $offset = 0) |
|
| 85 | + { |
|
| 86 | + $query = " |
|
| 87 | 87 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 88 | 88 | FROM `jpemeric_blog`.`post` |
| 89 | 89 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND |
| 90 | 90 | `ptlink`.`tag_id` = :tag_id |
| 91 | 91 | WHERE `display` = :is_active"; |
| 92 | - if ($limit != null) { |
|
| 93 | - $query .= " |
|
| 92 | + if ($limit != null) { |
|
| 93 | + $query .= " |
|
| 94 | 94 | LIMIT {$offset}, {$limit}"; |
| 95 | - } |
|
| 96 | - |
|
| 97 | - $bindings = [ |
|
| 98 | - 'tag_id' => $tag, |
|
| 99 | - 'is_active' => 1, |
|
| 100 | - ]; |
|
| 101 | - |
|
| 102 | - return $this |
|
| 103 | - ->connections |
|
| 104 | - ->getRead() |
|
| 105 | - ->fetchAll($query, $bindings); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getActivePostsCountByTag($tag) |
|
| 109 | - { |
|
| 110 | - $query = " |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $bindings = [ |
|
| 98 | + 'tag_id' => $tag, |
|
| 99 | + 'is_active' => 1, |
|
| 100 | + ]; |
|
| 101 | + |
|
| 102 | + return $this |
|
| 103 | + ->connections |
|
| 104 | + ->getRead() |
|
| 105 | + ->fetchAll($query, $bindings); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getActivePostsCountByTag($tag) |
|
| 109 | + { |
|
| 110 | + $query = " |
|
| 111 | 111 | SELECT COUNT(1) AS `count` |
| 112 | 112 | FROM `jpemeric_blog`.`post` |
| 113 | 113 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND |
| 114 | 114 | `ptlink`.`tag_id` = :tag_id |
| 115 | 115 | WHERE `display` = :is_active"; |
| 116 | - $bindings = [ |
|
| 117 | - 'tag_id' => $tag, |
|
| 118 | - 'is_active' => 1, |
|
| 119 | - ]; |
|
| 120 | - |
|
| 121 | - return $this |
|
| 122 | - ->connections |
|
| 123 | - ->getRead() |
|
| 124 | - ->fetchValue($query, $bindings); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function getActivePostsByCategory($category, $limit = null, $offset = 0) |
|
| 128 | - { |
|
| 129 | - $query = " |
|
| 116 | + $bindings = [ |
|
| 117 | + 'tag_id' => $tag, |
|
| 118 | + 'is_active' => 1, |
|
| 119 | + ]; |
|
| 120 | + |
|
| 121 | + return $this |
|
| 122 | + ->connections |
|
| 123 | + ->getRead() |
|
| 124 | + ->fetchValue($query, $bindings); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function getActivePostsByCategory($category, $limit = null, $offset = 0) |
|
| 128 | + { |
|
| 129 | + $query = " |
|
| 130 | 130 | SELECT `id`, `title`, `path`, `date`, `body`, `category` |
| 131 | 131 | FROM `jpemeric_blog`.`post` |
| 132 | 132 | WHERE `category` = :category AND `display` = :is_active"; |
| 133 | - if ($limit != null) { |
|
| 134 | - $query .= " |
|
| 133 | + if ($limit != null) { |
|
| 134 | + $query .= " |
|
| 135 | 135 | LIMIT {$offset}, {$limit}"; |
| 136 | - } |
|
| 137 | - |
|
| 138 | - $bindings = [ |
|
| 139 | - 'category' => $category, |
|
| 140 | - 'is_active' => 1, |
|
| 141 | - ]; |
|
| 142 | - |
|
| 143 | - return $this |
|
| 144 | - ->connections |
|
| 145 | - ->getRead() |
|
| 146 | - ->fetchAll($query, $bindings); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - public function getActivePostsCountByCategory($category) |
|
| 150 | - { |
|
| 151 | - $query = " |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $bindings = [ |
|
| 139 | + 'category' => $category, |
|
| 140 | + 'is_active' => 1, |
|
| 141 | + ]; |
|
| 142 | + |
|
| 143 | + return $this |
|
| 144 | + ->connections |
|
| 145 | + ->getRead() |
|
| 146 | + ->fetchAll($query, $bindings); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + public function getActivePostsCountByCategory($category) |
|
| 150 | + { |
|
| 151 | + $query = " |
|
| 152 | 152 | SELECT COUNT(1) AS `count` |
| 153 | 153 | FROM `jpemeric_blog`.`post` |
| 154 | 154 | WHERE `category` = :category AND `display` = :is_active"; |
| 155 | - $bindings = [ |
|
| 156 | - 'category' => $category, |
|
| 157 | - 'is_active' => 1, |
|
| 158 | - ]; |
|
| 159 | - |
|
| 160 | - return $this |
|
| 161 | - ->connections |
|
| 162 | - ->getRead() |
|
| 163 | - ->fetchValue($query, $bindings); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function getActivePostsByRelatedTags($post, $limit = 4) |
|
| 167 | - { |
|
| 168 | - $query = " |
|
| 155 | + $bindings = [ |
|
| 156 | + 'category' => $category, |
|
| 157 | + 'is_active' => 1, |
|
| 158 | + ]; |
|
| 159 | + |
|
| 160 | + return $this |
|
| 161 | + ->connections |
|
| 162 | + ->getRead() |
|
| 163 | + ->fetchValue($query, $bindings); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function getActivePostsByRelatedTags($post, $limit = 4) |
|
| 167 | + { |
|
| 168 | + $query = " |
|
| 169 | 169 | SELECT `id`, `title`, `path`, `date`, `body`, `category`, COUNT(1) AS `count` |
| 170 | 170 | FROM `jpemeric_blog`.`post` |
| 171 | 171 | INNER JOIN `jpemeric_blog`.`ptlink` ON `ptlink`.`post_id` = `post`.`id` AND |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | GROUP BY `id` |
| 186 | 186 | ORDER BY `count` DESC |
| 187 | 187 | LIMIT {$limit}"; |
| 188 | - $bindings = [ |
|
| 189 | - 'post' => $post, |
|
| 190 | - 'is_active' => 1, |
|
| 191 | - ]; |
|
| 192 | - |
|
| 193 | - return $this |
|
| 194 | - ->connections |
|
| 195 | - ->getRead() |
|
| 196 | - ->fetchAll($query, $bindings); |
|
| 197 | - } |
|
| 188 | + $bindings = [ |
|
| 189 | + 'post' => $post, |
|
| 190 | + 'is_active' => 1, |
|
| 191 | + ]; |
|
| 192 | + |
|
| 193 | + return $this |
|
| 194 | + ->connections |
|
| 195 | + ->getRead() |
|
| 196 | + ->fetchAll($query, $bindings); |
|
| 197 | + } |
|
| 198 | 198 | } |