Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Dec 28, 2015
2 parents c6ce88b + 0f36c1e commit 37eb1a3
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app/config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ storage_database =
default_timezone = Europe/Amsterdam

debug_enabled = 0
debug_maintenance_mode = 1
debug_maintenance_mode = 1

rights_add = mod, admin
8 changes: 4 additions & 4 deletions vendor/Devvoh/Components/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function __toString() {
// set select & what needs to be selected
$query[] = "SELECT " . $this->select;
// table
$query[] = "FROM " . $this->tableName;
$query[] = "FROM " . $this->pdoInstance->quote($this->tableName);

// Add the left joins
if (count($this->joins) > 0) {
Expand Down Expand Up @@ -250,7 +250,7 @@ public function __toString() {
} elseif ($this->action === 'delete') {

// set delete to the proper table
$query[] = "DELETE FROM " . $this->tableName;
$query[] = "DELETE FROM " . $this->pdoInstance->quote($this->tableName);

// now get the where clauses
if (count($this->where) > 0) {
Expand All @@ -270,7 +270,7 @@ public function __toString() {
} elseif ($this->action === 'update') {

// set update to the proper table
$query[] = "UPDATE " . $this->tableName;
$query[] = "UPDATE " . $this->pdoInstance->quote($this->tableName);

// now get the values
if (count($this->values) > 0) {
Expand All @@ -293,7 +293,7 @@ public function __toString() {
} elseif ($this->action === 'insert') {

// set insert to the proper table
$query[] = "INSERT INTO " . $this->tableName;
$query[] = "INSERT INTO " . $this->pdoInstance->quote($this->tableName);

// now get the values
if (count($this->values) > 0) {
Expand Down
149 changes: 149 additions & 0 deletions vendor/Devvoh/Components/Validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/**
* @package Devvoh
* @subpackage Components
* @subpackage Cli
* @license Validate
* @author Robin de Graaf <[email protected]>
* @copyright 2015 Robin de Graaf, devvoh webdevelopment
*/

namespace Devvoh\Components;

class Validate {

protected $customTypes = [];

/**
* If needed, custom validation types can be added, where closures are given that return true or false (and if not,
* will be cast to a boolean value anyway).
*
* @param null $type
* @param null $closure
* @return $this|bool
*/
public function addCustomType($type = null, $closure = null) {
if (!$type || !is_callable($closure)) {
return false;
}
$this->customTypes[$type] = $closure;
return $this;
}

/**
* Return the custom validation types currently set on Validate
*
* @return array
*/
public function getCustomTypes() {
return $this->customTypes;
}

/**
* Run validation on the $data given, using the validators in $validator. If $returnBool is true, return only
* an overall true/false value, otherwise return an array with every validation field set to a boolean value.
*
* @param null $data
* @param null $validator
* @param bool|true $returnBool
* @return array|bool
*/
public function run($data = null, $validator = null, $returnBool = true) {
if (!$data || !$validator) {
return false;
}

// We're only going to loop through the values specifically requiring validation. Our results array will
// not contain the values that we're not validating.
$results = [];
foreach ($validator as $key => $typeString) {

// If missing, don't need to do the type check
if (!array_key_exists($key, $data)) {
if (strpos($typeString, 'required')) {
$results[$key] = false;
continue;
}
continue;
}

$types = explode(':', $typeString);

// Remove required from our validation types, since we've already done it
$requiredKey = array_search('required', $types);
if ($requiredKey !== false) {
unset($types[$requiredKey]);
}

// And loop through the remaining types
foreach ($types as $type) {
// Some validation types require a parameter, which uses =
if (strpos($type, '=') !== false) {
$parts = explode('=', $type);
$type = $parts[0];
$param = $parts[1];
}

// Set success before validation
$results[$key] = true;

// And switch on type
switch ($type) {
case 'exactLength':
if (strlen($data[$key]) != $param) {
$results[$key] = false;
continue;
}
break;
case 'minLength':
if (strlen($data[$key]) < $param) {
$results[$key] = false;
continue;
}
break;
case 'maxLength':
if (strlen($data[$key]) > $param) {
$results[$key] = false;
continue;
}
break;
case 'int':
if (!is_int($data[$key])) {
$results[$key] = false;
continue;
}
break;
case 'string':
if (!is_string($data[$key])) {
$results[$key] = false;
continue;
}
break;
}
}

foreach ($this->getCustomTypes() as $type => $closure) {
if (strpos($typeString, $type) !== false) {
echo $type . '<br>';
$return = $closure($data[$key]);
var_dump($return);
}
}
}

// If we're only supposed to return a boolean value, we're going to have to loop through our results and
// return false if even one of them is false
if ($returnBool) {
foreach ($results as $result) {
if (!$result) {
return false;
}
}
return true;
}

// Return the results array
return $results;
}

}
21 changes: 21 additions & 0 deletions vendor/Devvoh/Fluid/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class App {
static protected $rights = null;
static protected $date = null;
static protected $curl = null;
static protected $validate = null;
static protected $currentModule = null;
static protected $modules = array();

Expand Down Expand Up @@ -76,6 +77,14 @@ public static function start() {
// Set the appropriate log directory & default file name
self::getLog()->setPath(self::getBaseDir() . 'var' . DS . 'log');

// And see if there's additional rights levels we should add
if (self::getConfig()->get('rights_add')) {
$toAdd = explode(',', self::getConfig()->get('rights_add'));
foreach ($toAdd as $right) {
self::getRights()->addRight(trim($right));
}
}

// Start the session
self::getSession()->startSession();
}
Expand Down Expand Up @@ -435,6 +444,18 @@ public static function getCurl() {
return self::$curl;
}

/**
* Returns (and possibly instantiates) the Validate instance
*
* @return \Devvoh\Components\Validate
*/
public static function getValidate() {
if (!self::$validate) {
self::$validate = new \Devvoh\Components\Validate();
}
return self::$validate;
}

/**
* Gets and returns the version stored in ./version
*
Expand Down
10 changes: 8 additions & 2 deletions vendor/Devvoh/Fluid/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@
*/
spl_autoload_register(function ($class) {
if (strpos($class, '_model') !== false) {
// Remove _model from the end in the most concrete way possible (str_replace might remove too many,
// and rtrim sometimes removed too much as well).
$classParts = explode('_', $class);
$modelName = $classParts[0];
$modelType = $classParts[1];
$lastPart = count($classParts) - 1;
if ($classParts[$lastPart] == 'model') {
unset($classParts[$lastPart]);
}
$modelName = implode('_', $classParts);

foreach (\Devvoh\Fluid\App::getModules() as $module) {
$path = $module['path'] . DS . 'model' . DS . $modelName . '.php';
if (is_file($path)) {
Expand Down
33 changes: 32 additions & 1 deletion vendor/Devvoh/Fluid/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Entity {
protected $tableName = null;
protected $tableKey = null;
protected $mapper = null;
protected $validator = [];

/**
* Generate a query set to use the current Entity's table name & key
Expand Down Expand Up @@ -68,7 +69,11 @@ public function save() {
$this->created_at = $now;
}
}
return App::getDatabase()->query($query);
$result = App::getDatabase()->query($query);
if ($result) {
$this->id = $query->getPdoInstance()->lastInsertId();
}
return $result;
}

/**
Expand Down Expand Up @@ -193,4 +198,30 @@ public function getMapper() {
return $this->mapper;
}

/**
* Set the validator array
*
* @param $validator
* @return $this
*/
public function setValidator($validator) {
$this->validator = $validator;
return $this;
}

/**
* Return the validator array
*
* @return array
*/
public function getValidator() {
return $this->validator;
}

public function validate($returnBool = true) {
$data = $this->toArray();
$validator = $this->getValidator();
return App::getValidate()->run($data, $validator, $returnBool);
}

}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.5
0.2.6

0 comments on commit 37eb1a3

Please sign in to comment.