Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit 49660dd

Browse files
author
Guillermo Cespedes
committed
- some improvements
- remove code examples that are not very relevant - new method to load entities without having to indicate namespace $this->loadMapper('Users');
1 parent 33af546 commit 49660dd

File tree

11 files changed

+91
-1117
lines changed

11 files changed

+91
-1117
lines changed

Particle/Apps/Controllers/indexController.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,74 +15,4 @@ public function index()
1515
{
1616
$this->view->show();
1717
}
18-
19-
public function testORM()
20-
{
21-
$personMapper = $this->spot->mapper('Particle\Apps\Entities\Person');
22-
$personMapper->migrate();
23-
24-
$bookMapper = $this->spot->mapper('Particle\Apps\Entities\Books');
25-
$bookMapper->migrate();
26-
27-
$sBirthday = '1995-02-24';
28-
$date = new \DateTime($sBirthday);
29-
30-
/* Relations (In this case de save the relation )*/
31-
$person = $personMapper->create(['PersonName' => 'Teo Muj Jr',
32-
'PersonMail' => 'mateomu18@gmail.com',
33-
'PersonBirthday' => $date,
34-
'PersonCountry' => 'Uruguay']);
35-
$newBook = $bookMapper->build(['BookTitle' => 'The Book 3',
36-
'BookAuthor' => 'Jon Doe',
37-
'BookDatePublished' => $date,
38-
'BookEdition' => 1,
39-
'PersonId' => $person->PersonId,
40-
]);
41-
$newBook->relation('person', $person);
42-
$bookMapper->save($newBook);
43-
$person->relation('books', $newBook);
44-
$personMapper->save($person, ['relations' => true]);
45-
$bookTitle = $person->books->BookTitle;
46-
47-
48-
return array('PersonId' => (int)$person->PersonId, 'BookTitle'=> $bookTitle);
49-
50-
// $booksP = $person->books;
51-
52-
/* Create enetity (Person) */
53-
// $person = $personMapper->first();
54-
// $newBook = $bookMapper->create([
55-
// 'PersonId' => $person->PersonaId,
56-
// 'BookTitle' => 'Harry Potter',
57-
// 'BookAuthor' => 'Guillermo Cespedes',
58-
// 'BookDatePublished' => $date,
59-
// 'BookEdition' => 1,
60-
// ]);
61-
62-
/* Delete && Update */
63-
// $bookDelete = $bookMapper->first();
64-
// $bookDelete->BookTitle = 'Title Change';
65-
// $this->view->assign('TitleUpd', $bookDelete->BookTitle);
66-
// $bookMapper->update($bookDelete);
67-
// $result = $bookMapper->delete($bookDelete);
68-
// if (!$result) {
69-
// return false;
70-
// } elseif (is_numeric($result)) {
71-
// $resultD = 'Delete success';
72-
// }
73-
74-
/* Events (if personId <= 0 exception)*/
75-
// $person = $personMapper->create(['PersonId' => 0,
76-
// 'PersonName' => 'Teo Muj Jr',
77-
// 'PersonMail' => 'mateomu18@gmail.com',
78-
// 'PersonBirthday' => $date,
79-
// 'PersonCountry' => 'Uruguay']);
80-
81-
/* Custom Mapper */
82-
// $owners1stEditionBooks = $personMapper->libros1eraEdicion();
83-
84-
/* Retrive all */
85-
// $people = $personMapper->all();
86-
// $books = $bookMapper->all();
87-
}
8818
}

Particle/Apps/Settings/global.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
if (!defined('FROMMAIL')) {
6565
define('FROMMAIL', 'mail@localhost.com');
6666
}
67-
if (!defined('VarGlobalJS')) {
68-
define('VarGlobalJS', '
69-
var VarGlobalJS = "1";
67+
if (!defined('VARGLOBALJS')) {
68+
define('VARGLOBALJS', '
69+
var VARGLOBALJS = "1";
7070
');
7171
}

Particle/Apps/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"require": {
3-
"phpmailer/phpmailer": "^6.0"
3+
"phpmailer/phpmailer": "dev-master"
44
}
55
}

Particle/Apps/composer.lock

Lines changed: 0 additions & 84 deletions
This file was deleted.

Particle/Core/Controller.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,18 @@ final protected static function getInt($key, $array = null, $default = 0)
142142
return 0;
143143
}
144144

145-
final protected static function getParam($key, $array = null, $default = false)
145+
final protected static function getParam($key, $array = null, $default = false, $filterValidate = null)
146146
{
147147
if (is_null($array)) {
148148
$array = $_REQUEST;
149149
}
150150

151151
if (isset($array[$key])) {
152+
if (!empty($filterValidate)) {
153+
if (!filter_var($array[$key], $filterValidate)) {
154+
return $default;
155+
}
156+
}
152157
return $array[$key];
153158
} else {
154159
return $default;
@@ -224,13 +229,4 @@ final protected static function uploadFile($File, $FullPatch, $allowedExts = fal
224229
echo 'Error - Invalid File';
225230
}
226231
}
227-
228-
final protected static function checkDateRange($start_date, $end_date, $evaluame)
229-
{
230-
// data format YYYY-mm-dd
231-
$start_ts = strtotime($start_date);
232-
$end_ts = strtotime($end_date);
233-
$user_ts = strtotime($evaluame);
234-
return (($user_ts >= $start_ts) && ($user_ts <= $end_ts));
235-
}
236232
}

Particle/Core/Request.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ final class Request
7373
*/
7474
private $flagMapping = false;
7575

76-
public function __construct($requestTesting = null)
76+
public function __construct($requestTesting = null, $methodTesting = null, $optionsTesting = null)
7777
{
7878
$this->request = null;
7979

@@ -83,6 +83,9 @@ public function __construct($requestTesting = null)
8383
$this->request = $requestTesting;
8484
}
8585

86+
if (!empty($optionsTesting) && is_array($optionsTesting) && !empty($methodTesting) && ($methodTesting === 'GET' || $methodTesting === 'POST' || $methodTesting === 'PUT')) {
87+
$this->setRequestGlobals($methodTesting, $optionsTesting);
88+
}
8689
if (!empty($this->request)) {
8790
$this->loadClassAttributes($this->xmlSetMapping());
8891
}
@@ -269,10 +272,10 @@ final private function loadClassAttributes($aMapping = false)
269272
$requestTemp = $this->request;
270273

271274
$requestExplode = explode('/', $requestTemp);
272-
273-
if(empty($requestExplode[0])){
274-
// The first position is empty. It is eliminated
275-
unset($requestExplode[0]);
275+
276+
if (empty($requestExplode[0])) {
277+
// The first position is empty. It is eliminated
278+
unset($requestExplode[0]);
276279
}
277280

278281
$this->controller = strtolower(array_shift($requestExplode));
@@ -446,4 +449,36 @@ public function getArgs()
446449
{
447450
return $this->args;
448451
}
452+
453+
/**
454+
* Sets php super globals so other packages would have access to them on tests context
455+
* @param string $method [GET|POST|PUT]
456+
* @param array $options
457+
*/
458+
private function setRequestGlobals($method, $options = array())
459+
{
460+
$_SERVER['REQUEST_METHOD'] = $method;
461+
if (!empty($options)) {
462+
if ($method === "GET") {
463+
foreach ($options as $key => $value) {
464+
$_GET[$key] = $value;
465+
}
466+
}
467+
if ($method === "POST") {
468+
foreach ($options as $key => $value) {
469+
$_POST[$key] = $value;
470+
}
471+
}
472+
if ($method === "PUT") {
473+
foreach ($options as $key => $value) {
474+
$_POST[$key] = $value;
475+
}
476+
}
477+
}
478+
}
479+
public function closeRequestTesting()
480+
{
481+
$_GET = array();
482+
$_POST = array();
483+
}
449484
}

Particle/Core/Security.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ final public static function filterSql($sql, $html = true, $default = false)
112112
}
113113
}
114114

115+
final public static function validateDate($date, $format = 'Y-m-d')
116+
{
117+
$d = DateTime::createFromFormat($format, $date);
118+
return $d && $d->format($format) == $date;
119+
}
120+
121+
final public static function checkDateRange($start_date, $end_date, $evaluame)
122+
{
123+
// data format YYYY-mm-dd
124+
$start_ts = strtotime($start_date);
125+
$end_ts = strtotime($end_date);
126+
$user_ts = strtotime($evaluame);
127+
return (($user_ts >= $start_ts) && ($user_ts <= $end_ts));
128+
}
129+
130+
115131
final public static function validateEmail($email)
116132
{
117133
$email = trim($email);
@@ -419,8 +435,11 @@ final public static function getIPNoFORWARDED()
419435
return $client_ip;
420436
}
421437

422-
final public static function validArrayIsNumeric($aInput)
438+
final public static function isValidArrayIsNumeric($aInput)
423439
{
440+
if (empty($aInput)) {
441+
return false;
442+
}
424443
foreach ($aInput as $key => $value) {
425444
if (!is_numeric($value)) {
426445
return false;
@@ -429,6 +448,12 @@ final public static function validArrayIsNumeric($aInput)
429448
return true;
430449
}
431450

451+
final public static function isValidJSON($string)
452+
{
453+
json_decode($string);
454+
return (json_last_error() == JSON_ERROR_NONE);
455+
}
456+
432457
final public static function getIntentoBruteForce($nameZone)
433458
{
434459
$intento = 0;

Particle/Core/SpotLoad.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ public function __construct()
2828
'password' => DB_PASS_CONFIG,
2929
'host' => DB_HOST_CONFIG,
3030
'driver' => DB_DRIVER_CONFIG,
31+
'charset' => 'utf8'
3132
]);
3233

3334
self::$spotInstance = new \Spot\Locator($cfg);
3435
}
3536
}
37+
38+
public function loadMapper($strEntity)
39+
{
40+
if (!isset(self::$spotInstance) || !(self::$spotInstance instanceof \Spot\Locator)) {
41+
return false;
42+
}
43+
return self::$spotInstance->mapper('Particle\Apps\Entities\\'.$strEntity);
44+
}
3645
}

Particle/Core/View.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ public function show($view = false, $customController = false, $return = false,
206206
$this->assign('_layoutParams', $_params);
207207
}
208208

209-
if (defined('VarGlobalJS')) {
210-
$this->assign('varGlobalToJs', VarGlobalJS);
209+
if (defined('VARGLOBALJS')) {
210+
$this->assign('varGlobalToJs', VARGLOBALJS);
211211
}
212212

213213
$sHeader = $this->fetch('header.tpl', self::$cacheKey);

Particle/Core/composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"require": {
3-
"vlucas/spot2": "~2.0",
4-
"phpfastcache/phpfastcache": "^6.1",
5-
"smarty/smarty": "^3.1",
6-
"stefangabos/zebra_session": "^2.1"
3+
"smarty/smarty": "dev-master",
4+
"vlucas/spot2": "dev-master",
5+
"phpfastcache/phpfastcache": "dev-master",
6+
"sobstel/sesshin": "dev-master"
77
}
88
}

0 commit comments

Comments
 (0)