From 36c0d02dfc57e3a10ba7eaa71e22ee9b76957dbc Mon Sep 17 00:00:00 2001 From: Robin de Graaf Date: Fri, 4 Mar 2016 21:45:30 +0100 Subject: [PATCH 1/3] Simplified doc blocks --- app/modules/App/Controller/Home.php | 1 - app/modules/App/Model/Users.php | 1 - app/modules/App/Routes.php | 1 - app/modules/Core/Controller/Base.php | 1 - public/index.php | 1 - vendor/Devvoh/Components/Autoloader.php | 4 +--- vendor/Devvoh/Components/Cli.php | 4 +--- vendor/Devvoh/Components/Curl.php | 4 +--- vendor/Devvoh/Components/Database.php | 4 +--- vendor/Devvoh/Components/Date.php | 4 +--- vendor/Devvoh/Components/Debug.php | 4 +--- vendor/Devvoh/Components/Dock.php | 4 +--- vendor/Devvoh/Components/GetSet.php | 4 +--- vendor/Devvoh/Components/Hook.php | 4 +--- vendor/Devvoh/Components/Log.php | 4 +--- vendor/Devvoh/Components/Query.php | 4 +--- vendor/Devvoh/Components/Response.php | 4 +--- vendor/Devvoh/Components/Rights.php | 4 +--- vendor/Devvoh/Components/Router.php | 4 +--- vendor/Devvoh/Components/SessionMessage.php | 4 +--- vendor/Devvoh/Components/Validate.php | 4 +--- vendor/Devvoh/Fluid/App.php | 4 +--- vendor/Devvoh/Fluid/App/Config.php | 5 +---- vendor/Devvoh/Fluid/App/View.php | 5 +---- vendor/Devvoh/Fluid/Bootstrap.php | 4 +--- vendor/Devvoh/Fluid/Entity.php | 4 +--- vendor/Devvoh/Fluid/Repository.php | 4 +--- 27 files changed, 22 insertions(+), 73 deletions(-) diff --git a/app/modules/App/Controller/Home.php b/app/modules/App/Controller/Home.php index 90879767..95c94e6a 100644 --- a/app/modules/App/Controller/Home.php +++ b/app/modules/App/Controller/Home.php @@ -1,7 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Cli.php b/vendor/Devvoh/Components/Cli.php index 9ec431e9..4102d7e5 100644 --- a/vendor/Devvoh/Components/Cli.php +++ b/vendor/Devvoh/Components/Cli.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Curl.php b/vendor/Devvoh/Components/Curl.php index dd5358a9..ba2700e8 100644 --- a/vendor/Devvoh/Components/Curl.php +++ b/vendor/Devvoh/Components/Curl.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Database.php b/vendor/Devvoh/Components/Database.php index f6d285a0..98a0bc34 100644 --- a/vendor/Devvoh/Components/Database.php +++ b/vendor/Devvoh/Components/Database.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Date.php b/vendor/Devvoh/Components/Date.php index b242cfad..eb88147c 100644 --- a/vendor/Devvoh/Components/Date.php +++ b/vendor/Devvoh/Components/Date.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Debug.php b/vendor/Devvoh/Components/Debug.php index 8c1a401e..ecbc9e7e 100644 --- a/vendor/Devvoh/Components/Debug.php +++ b/vendor/Devvoh/Components/Debug.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Dock.php b/vendor/Devvoh/Components/Dock.php index ce00af78..5297c2dc 100644 --- a/vendor/Devvoh/Components/Dock.php +++ b/vendor/Devvoh/Components/Dock.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/GetSet.php b/vendor/Devvoh/Components/GetSet.php index 3742c792..38812413 100644 --- a/vendor/Devvoh/Components/GetSet.php +++ b/vendor/Devvoh/Components/GetSet.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Hook.php b/vendor/Devvoh/Components/Hook.php index 4549c507..4808dd44 100644 --- a/vendor/Devvoh/Components/Hook.php +++ b/vendor/Devvoh/Components/Hook.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Log.php b/vendor/Devvoh/Components/Log.php index f94045db..d5ae1cdd 100644 --- a/vendor/Devvoh/Components/Log.php +++ b/vendor/Devvoh/Components/Log.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Query.php b/vendor/Devvoh/Components/Query.php index 7150c2a9..8d1b4c6a 100644 --- a/vendor/Devvoh/Components/Query.php +++ b/vendor/Devvoh/Components/Query.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Response.php b/vendor/Devvoh/Components/Response.php index 3b695efe..aed34b15 100644 --- a/vendor/Devvoh/Components/Response.php +++ b/vendor/Devvoh/Components/Response.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Rights.php b/vendor/Devvoh/Components/Rights.php index 8588d5d6..cea440c5 100644 --- a/vendor/Devvoh/Components/Rights.php +++ b/vendor/Devvoh/Components/Rights.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Router.php b/vendor/Devvoh/Components/Router.php index 157746c0..1f51f543 100644 --- a/vendor/Devvoh/Components/Router.php +++ b/vendor/Devvoh/Components/Router.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/SessionMessage.php b/vendor/Devvoh/Components/SessionMessage.php index 68f59b2f..c276caac 100644 --- a/vendor/Devvoh/Components/SessionMessage.php +++ b/vendor/Devvoh/Components/SessionMessage.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Components/Validate.php b/vendor/Devvoh/Components/Validate.php index ffa4840c..a16b59c0 100644 --- a/vendor/Devvoh/Components/Validate.php +++ b/vendor/Devvoh/Components/Validate.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Fluid/App.php b/vendor/Devvoh/Fluid/App.php index 66666941..e6b94c5c 100644 --- a/vendor/Devvoh/Fluid/App.php +++ b/vendor/Devvoh/Fluid/App.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Fluid/App/Config.php b/vendor/Devvoh/Fluid/App/Config.php index 00a97ee4..409bc707 100644 --- a/vendor/Devvoh/Fluid/App/Config.php +++ b/vendor/Devvoh/Fluid/App/Config.php @@ -1,9 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Fluid/App/View.php b/vendor/Devvoh/Fluid/App/View.php index fc9f31eb..0455762f 100644 --- a/vendor/Devvoh/Fluid/App/View.php +++ b/vendor/Devvoh/Fluid/App/View.php @@ -1,9 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Fluid/Bootstrap.php b/vendor/Devvoh/Fluid/Bootstrap.php index 86c9fcf6..12c42792 100644 --- a/vendor/Devvoh/Fluid/Bootstrap.php +++ b/vendor/Devvoh/Fluid/Bootstrap.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Fluid/Entity.php b/vendor/Devvoh/Fluid/Entity.php index b006ae79..4c658b2c 100644 --- a/vendor/Devvoh/Fluid/Entity.php +++ b/vendor/Devvoh/Fluid/Entity.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment diff --git a/vendor/Devvoh/Fluid/Repository.php b/vendor/Devvoh/Fluid/Repository.php index 3309eebb..51bbfad2 100644 --- a/vendor/Devvoh/Fluid/Repository.php +++ b/vendor/Devvoh/Fluid/Repository.php @@ -1,8 +1,6 @@ * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment From 94443c2a2253b369ca91a35b9893eeaa42e6b002 Mon Sep 17 00:00:00 2001 From: Robin de Graaf Date: Fri, 4 Mar 2016 21:46:54 +0100 Subject: [PATCH 2/3] Added sendResponse to Response object. Realize the Response needs much future work. --- vendor/Devvoh/Components/Response.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vendor/Devvoh/Components/Response.php b/vendor/Devvoh/Components/Response.php index aed34b15..75ee301b 100644 --- a/vendor/Devvoh/Components/Response.php +++ b/vendor/Devvoh/Components/Response.php @@ -144,6 +144,18 @@ public function setContent($content) { return $this; } + /** + * Send content immediately + * + * @param $content + * + * @return $this + */ + public function sendContent($content) { + echo $content; + return $this; + } + /** * Prepend data to content * From 0a1654b7a0bec58e4c7b179669c3a92a55f53a5d Mon Sep 17 00:00:00 2001 From: Robin de Graaf Date: Wed, 23 Mar 2016 09:29:17 +0100 Subject: [PATCH 3/3] Added back in improvements from implementation project --- vendor/Devvoh/Components/Mailer.php | 113 ++++++++++++++++++++ vendor/Devvoh/Components/Query.php | 40 +++++-- vendor/Devvoh/Components/SessionMessage.php | 4 +- vendor/Devvoh/Fluid/App.php | 42 +++++++- vendor/Devvoh/Fluid/App/Config.php | 4 + vendor/Devvoh/Fluid/Entity.php | 7 +- vendor/Devvoh/Fluid/Repository.php | 42 ++++++++ version | 2 +- 8 files changed, 236 insertions(+), 18 deletions(-) create mode 100644 vendor/Devvoh/Components/Mailer.php diff --git a/vendor/Devvoh/Components/Mailer.php b/vendor/Devvoh/Components/Mailer.php new file mode 100644 index 00000000..b796cb36 --- /dev/null +++ b/vendor/Devvoh/Components/Mailer.php @@ -0,0 +1,113 @@ + + * @copyright 2015-2016, Robin de Graaf, devvoh webdevelopment + */ + +namespace Devvoh\Components; + +class Mailer { + + protected $to = []; + protected $from = null; + protected $subject = null; + protected $body = null; + protected $headers = []; + protected $isHTML = false; + + public function setTo($to) { + if (!is_array($to)) { + $to = [$to]; + } + $this->to = $to; + return $this; + } + + public function getTo() { + return $this->to; + } + + public function addTo($to) { + $this->to[] = $to; + return $this; + } + + public function setSubject($subject) { + $this->subject = $subject; + return $this; + } + + public function getSubject() { + return $this->subject; + } + + public function setBody($body) { + $this->body = $body; + return $this; + } + + public function getBody() { + return $this->body; + } + + public function setHeaders($headers) { + if (!is_array($headers)) { + $headers = [$headers]; + } + $this->headers = $headers; + return $this; + } + + public function getHeaders() { + return $this->headers; + } + + public function addHeader($header) { + $this->headers[] = $header; + return $this; + } + + public function setFrom($from) { + $this->from = $from; + } + + public function getFrom() { + return $this->from; + } + + public function setHTML($active) { + $this->isHTML = (bool)$active; + } + + public function isHTML() { + return $this->isHTML; + } + + public function send() { + $to = $this->getTo(); + if ($to) { + $to = implode(',', $this->getTo()); + } + // Get From, and set Reply-To as well if it's set + // @todo add setReplyTo & getReplyTo, as well as CC/BCC + if ($this->getFrom()) { + $this->addHeader('From: ' . $this->getFrom()); + $this->addHeader('Reply-To: ' . $this->getFrom()); + } + if ($this->isHTML()) { + $this->addHeader('MIME-Version: 1.0'); + $this->addHeader('Content-type: text/html; charset=utf-8'); + } + $headers = $this->getHeaders(); + if (count($headers) > 0) { + $headers = implode("\r\n", $this->getHeaders()); + } + $subject = $this->getSubject(); + $body = $this->getBody(); + + return mail($to, $subject, $body, $headers); + } + +} \ No newline at end of file diff --git a/vendor/Devvoh/Components/Query.php b/vendor/Devvoh/Components/Query.php index 8d1b4c6a..387cca60 100644 --- a/vendor/Devvoh/Components/Query.php +++ b/vendor/Devvoh/Components/Query.php @@ -135,6 +135,15 @@ public function setAction($action) { return $this; } + /** + * Return the action + * + * @return string + */ + public function getAction() { + return $this->action; + } + /** * In case of a select, what we're going to select (default *) * @@ -183,7 +192,7 @@ public function join($table, $condition, $value = null) { * @return $this */ public function addValue($key, $value) { - $this->values[] = ['key' => $key, 'value' => $value]; + $this->values[$key] = $value; return $this; } @@ -315,8 +324,6 @@ public function __toString() { } } $query[] = "WHERE " . implode(' AND ', $wheres); - } else { - $query = []; } } elseif ($this->action === 'update') { @@ -331,13 +338,18 @@ public function __toString() { $tableKeyValue = null; $values = []; - foreach ($this->values as $value) { + foreach ($this->values as $key => $value) { // skip id, since we'll use that as a where condition - if ($value['key'] !== $this->tableKey) { - $values[] = "'" . $value['key'] . "'=" . $this->pdoInstance->quote($value['value']); + if ($key !== $this->tableKey) { + if ($value === null) { + $correctValue = 'NULL'; + } else { + $correctValue = $this->pdoInstance->quote($value); + } + $values[] = "'" . $key . "'=" . $correctValue; } else { - $tableKey = $value['key']; - $tableKeyValue = $value['value']; + $tableKey = $key; + $tableKeyValue = $value; } } $query[] = "SET " . implode(',', $values); @@ -356,9 +368,15 @@ public function __toString() { $keys = []; $values = []; - foreach ($this->values as $value) { - $keys[] = "'" . $value['key'] . "'"; - $values[] = $this->pdoInstance->quote($value['value']); + foreach ($this->values as $key => $value) { + $keys[] = "'" . $key . "'"; + + if ($value === null) { + $correctValue = 'NULL'; + } else { + $correctValue = $this->pdoInstance->quote($value); + } + $values[] = $correctValue; } $query[] = "(" . implode(',', $keys) . ")"; diff --git a/vendor/Devvoh/Components/SessionMessage.php b/vendor/Devvoh/Components/SessionMessage.php index c276caac..bb11b0d8 100644 --- a/vendor/Devvoh/Components/SessionMessage.php +++ b/vendor/Devvoh/Components/SessionMessage.php @@ -25,7 +25,9 @@ class SessionMessage { */ public function __construct() { $this->initSession(); - $this->messages = $this->session->get('messages'); + if (is_array($this->session->get('messages'))) { + $this->messages = $this->session->get('messages'); + } } /** diff --git a/vendor/Devvoh/Fluid/App.php b/vendor/Devvoh/Fluid/App.php index e6b94c5c..5bf4241a 100644 --- a/vendor/Devvoh/Fluid/App.php +++ b/vendor/Devvoh/Fluid/App.php @@ -55,6 +55,11 @@ class App { */ static protected $log = null; + /** + * @var null|\Devvoh\Components\Mailer + */ + static protected $mailer = null; + /** * @var null|\Devvoh\Components\GetSet */ @@ -306,6 +311,15 @@ public static function getUrl($path = null) { return $url; } + /** + * Returns the current url + * + * @return null|string + */ + public static function getCurrentUrl() { + return self::getUrl($_GET['path']); + } + /** * Enables debug mode, which will display errors. Errors are always logged (see Bootstrap.php) */ @@ -391,6 +405,18 @@ public static function getLog() { return self::$log; } + /** + * Returns (and possibly instantiates) the Mailer instance + * + * @return \Devvoh\Components\Mailer + */ + public static function getMailer() { + if (!self::$mailer) { + self::$mailer = new \Devvoh\Components\Mailer(); + } + return self::$mailer; + } + /** * Returns (and possibly instantiates) the GetSet instance with context session * @@ -634,14 +660,24 @@ public static function createQuery() { public static function createRepository($entityName = null) { $repository = new \Devvoh\Fluid\Repository(); - // Build the proper entity name - $entityName = '\\' . self::getCurrentModule() . '\\Model\\' . $entityName; + $entity = self::createEntity($entityName); - $entity = new $entityName(); $repository->setEntity($entity); return $repository; } + public static function createEntity($entityName = null) { + // Loop through models trying to find the appropriate class + foreach (self::getModules() as $module) { + $entityNameComplete = '\\' . $module['name'] . '\\Model\\' . $entityName; + if (class_exists($entityNameComplete)) { + $entity = new $entityNameComplete(); + break; + } + } + return $entity; + } + /** * Match the route using the router and store the result in self::$route * diff --git a/vendor/Devvoh/Fluid/App/Config.php b/vendor/Devvoh/Fluid/App/Config.php index 409bc707..e3716976 100644 --- a/vendor/Devvoh/Fluid/App/Config.php +++ b/vendor/Devvoh/Fluid/App/Config.php @@ -42,4 +42,8 @@ public function load() { return $this; } + public function getBool($key) { + return (bool)$this->get($key); + } + } \ No newline at end of file diff --git a/vendor/Devvoh/Fluid/Entity.php b/vendor/Devvoh/Fluid/Entity.php index 4c658b2c..88499108 100644 --- a/vendor/Devvoh/Fluid/Entity.php +++ b/vendor/Devvoh/Fluid/Entity.php @@ -88,7 +88,7 @@ public function save() { } } $result = App::getDatabase()->query($query); - if ($result) { + if ($result && $query->getAction() === 'insert') { $this->id = $query->getPdoInstance()->lastInsertId(); } return $result; @@ -103,9 +103,12 @@ public function toArray() { $array = (array)$this; // Remove protected values & null values, let the database sort those out foreach ($array as $key => $value) { - if (strpos($key, '*') || $value === null) { + if (strpos($key, '*')) { unset($array[$key]); } + if ($value !== 0 && empty($value)) { + $value = null; + } } // If there's a mapper set, also map the array around if ($this->getMapper()) { diff --git a/vendor/Devvoh/Fluid/Repository.php b/vendor/Devvoh/Fluid/Repository.php index 51bbfad2..f84fdc35 100644 --- a/vendor/Devvoh/Fluid/Repository.php +++ b/vendor/Devvoh/Fluid/Repository.php @@ -22,6 +22,16 @@ class Repository { */ protected $onlyCount = false; + /** + * @var array + */ + protected $orderBy = []; + + /** + * @var null|int + */ + protected $limit = []; + /** * Generate a query set to use the current Entity's table name & key * @@ -86,6 +96,12 @@ public function getByConditions($conditionsArray) { foreach ($conditionsArray as $condition => $value) { $query->where($condition, $value); } + if (count($this->orderBy)) { + $query->orderBy($this->orderBy['key'], $this->orderBy['direction']); + } + if (count($this->limit)) { + $query->limit($this->limit['limit'], $this->limit['offset']); + } $result = App::getDatabase()->query($query)->fetchAll(\PDO::FETCH_ASSOC); $entities = []; @@ -95,6 +111,32 @@ public function getByConditions($conditionsArray) { return $entities; } + /** + * Allow multiple orders by $key in $direction + * + * @param $key + * @param $direction + * + * @return $this + */ + public function orderBy($key, $direction = 'DESC') { + $this->orderBy = ['key' => $key, 'direction' => $direction]; + return $this; + } + + /** + * Sets the limit + * + * @param int $limit + * @param int $offset + * + * @return $this + */ + public function limit($limit, $offset = null) { + $this->limit = ['limit' => $limit, 'offset' => $offset]; + return $this; + } + /** * Returns all rows matching specific condition given * diff --git a/version b/version index d15723fb..1c09c74e 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.3.2 +0.3.3