Skip to content

Commit

Permalink
Version 2.24, released 06/01/2014.
Browse files Browse the repository at this point in the history
[Refactor] - Mayor change. After intense struggles and researches, decided to use PHP ActiveRecord. Because of this, deleted all Database and Model related constructions used so far. I am aiming to implement my own PHP ActiveRecord technology for the third Hecnel Framework version.
[Feature] - Test 4 is designed to be the testing workspace for multiple model work. However, as PHP ActiveRecord comes to play, it is halfway implemented. To be reworked in future.
  • Loading branch information
HectorOrdonez committed Jan 6, 2014
1 parent 1132965 commit 40005e0
Show file tree
Hide file tree
Showing 146 changed files with 15,920 additions and 1,131 deletions.
7 changes: 6 additions & 1 deletion application/config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
define ('_DEFAULT_CONTROLLER', 'index');
define ('_DEFAULT_METHOD', 'index');
define ('_ERROR_CONTROLLER', 'Error');
define ('_EXCEPTION_METHOD', 'exception');
define ('_EXCEPTION_METHOD', 'exception');

/**
* Config required for ActiveRecord. It disables its autoloading function.
*/
define ('PHP_ACTIVERECORD_AUTOLOAD_DISABLE', true);
10 changes: 7 additions & 3 deletions application/controllers/releaseLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ public function __construct()
parent::__construct();

// Setting version under construction
$this->_setDevelopmentVersion('2.23', '04/01/2014', array(
'[Refactor] - Modified libraries concept to Service concepts. A Service is tightly related to a controller. It stores intelligence regarding what to do with validated information, which models request a CRUD, and informs the controller about the message to put into the related view.',
'[Refactor] - Modified Hecnel Framework in order to use the new Model architecture.'
$this->_setDevelopmentVersion('2.24', '06/01/2014', array(
'[Refactor] - Mayor change. After intense struggles and researches, decided to use PHP ActiveRecord. Because of this, deleted all Database and Model related constructions used so far. I am aiming to implement my own PHP ActiveRecord technology for the third Hecnel Framework version.',
'[Feature] - Test 4 is designed to be the testing workspace for multiple model work. However, as PHP ActiveRecord comes to play, it is halfway implemented. To be reworked in future.',
));

// Setting Historical Log of releases
$this->_addHistoryLog('2.23', '04/01/2014', array(
'[Refactor] - Modified libraries concept to Service concepts. A Service is tightly related to a controller. It stores intelligence regarding what to do with validated information, which models request a CRUD, and informs the controller about the message to put into the related view.',
'[Refactor] - Modified Hecnel Framework in order to use the new Model architecture.'
));
$this->_addHistoryLog('2.22', '04/01/2014', array(
'[Refactor] - Mayor change in Model architecture. Now all models extend the same Model object, which handles all commands that a Model offers and instantiates and communicates with the Database.',
'[Refactor] - Major change in Database architecture. Now it is allowed to have different storing systems.',
Expand Down
69 changes: 13 additions & 56 deletions application/controllers/test3.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use application\engine\Controller;
use application\models\Dog;
use engine\Input;
use engine\Model;
use engine\drivers\Exceptions\ModelException;
use engine\drivers\Exceptions\RuleException;

Expand Down Expand Up @@ -58,14 +57,14 @@ public function makeADog()
$inputDogName->validate();
$inputDogAge->validate();
$inputDogBreed->validate();

$dog = Dog::create(array(
'name' => $inputDogName->getValue(),
'age' => $inputDogAge->getValue(),
'breed' => $inputDogBreed->getValue()
));

$dog = new Dog();
$dog->name = $inputDogName->getValue();
$dog->age = $inputDogAge->getValue();
$dog->breed = $inputDogBreed->getValue();
$dog->save();

echo json_encode(array('id' => $dog->getId()));
echo json_encode(array('id' => $dog->id));
} catch (RuleException $rEx) {
header("HTTP/1.1 400 Could not make a dog.");
echo json_encode(array('errorMessage' => $rEx->getMessage()));
Expand All @@ -77,24 +76,8 @@ public function makeADog()
*/
public function getADog()
{
try {
$dog = new Dog();
$dog->find();
} catch (ModelException $mEx) {
switch ($mEx->getCode()) {
case Model::ERR_RECORDS_FOUND:
header("HTTP/1.1 400 Could not find a dog.");
echo json_encode(array('errorMessage' => 'Could not find a dog.'));
exit;
break;
default:
header("HTTP/1.1 400 Could not make a dog.");
echo json_encode(array('errorMessage' => 'Unexpected error: ' . $mEx->getMessage()));
exit;
}
}

echo json_encode($dog->toArray());
$dog = Dog::first();
echo json_encode($dog->attributes());
}

/**
Expand Down Expand Up @@ -125,9 +108,9 @@ public function changeADog()
$inputDogName->validate();
$inputDogAge->validate();
$inputDogBreed->validate();

$dog = new Dog();
$dog->find(array('id' => $inputDogId->getValue()));
$dog = Dog::find(array('id'=> $inputDogId->getValue()));

$dog->name = $inputDogName->getValue();
$dog->age = $inputDogAge->getValue();
$dog->breed = $inputDogBreed->getValue();
Expand All @@ -136,20 +119,7 @@ public function changeADog()
} catch (RuleException $rEx) {
header("HTTP/1.1 400 Could not change a dog.");
echo json_encode(array('errorMessage' => $rEx->getMessage()));
} catch (ModelException $mEx) {
switch ($mEx->getCode()) {
case Model::ERR_RECORDS_FOUND:
header("HTTP/1.1 400 Dog does not exist.");
echo json_encode(array('errorMessage' => 'Dog you are trying to change does not exist.'));
exit;
break;
default:
header("HTTP/1.1 400 Could not change a dog.");
echo json_encode(array('errorMessage' => 'Unexpected error: ' . $mEx->getMessage()));
exit;
}
}

}

/**
Expand All @@ -164,25 +134,12 @@ public function sayByeToADog()
try {
$inputDogId->validate();

$dog = new Dog();
$dog->find(array('id' => $inputDogId->getValue()));
$dog = Dog::find(array('id' => $inputDogId->getValue()));
$dog->delete();

} catch (RuleException $rEx) {
header("HTTP/1.1 400 Could not delete a dog.");
echo json_encode(array('errorMessage' => $rEx->getMessage()));
} catch (ModelException $mEx) {
switch ($mEx->getCode()) {
case Model::ERR_RECORDS_FOUND:
header("HTTP/1.1 400 Dog does not exist.");
echo json_encode(array('errorMessage' => 'Dog you are trying to delete does not exist.'));
exit;
break;
default:
header("HTTP/1.1 400 Could not delete a dog.");
echo json_encode(array('errorMessage' => 'Unexpected error: ' . $mEx->getMessage()));
exit;
}
}
}
}
160 changes: 160 additions & 0 deletions application/controllers/test4.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
namespace application\controllers;

use application\engine\Controller;
use application\models\Dog;
use engine\Input;
use engine\ModelCollection;
use engine\drivers\Exceptions\ModelException;
use engine\drivers\Exceptions\RuleException;

class Test4 extends Controller
{
Expand All @@ -23,6 +28,161 @@ public function __construct()

public function index()
{
$this->_view->addLibrary('js', 'application/views/tests/test4/js/test4.js');
$this->_view->addLibrary('css', 'application/views/tests/test4/css/test4.css');

$this->_view->addChunk('tests/test4/index');
}

/**
* CRUD - Create
*/
public function createDogs()
{
$inputDogName = Input::build('Text', 'dogName')
->addRule('minLength', 3)
->addRule('maxLength', 12);
$inputDogAge = Input::build('Number', 'dogAge')
->addRule('min', 0)
->addRule('max', 100)
->addRule('isInt');
$inputDogBreed = Input::build('Select', 'dogBreed')
->addRule('availableOptions', array(
'germanSheppard',
'siberianHusky',
'biggles',
'borderCollie'
));

try {
$inputDogName->validate();
$inputDogAge->validate();
$inputDogBreed->validate();

$dogCollection = new ModelCollection(new Dog);
$dogCollection->
$dog->name = $inputDogName->getValue();
$dog->age = $inputDogAge->getValue();
$dog->breed = $inputDogBreed->getValue();
$dog->save();

echo json_encode(array('id' => $dog->getId()));
} catch (RuleException $rEx) {
header("HTTP/1.1 400 Could not make a dog.");
echo json_encode(array('errorMessage' => $rEx->getMessage()));
}
}

/**
* CRUD - Read
*/
public function getDoggies()
{
try {
$dog = new Dog();
$dog->find();
} catch (ModelException $mEx) {
switch ($mEx->getCode()) {
case Dog::ERR_RECORDS_FOUND:
header("HTTP/1.1 400 Could not find a dog.");
echo json_encode(array('errorMessage' => 'Could not find a dog.'));
exit;
break;
default:
header("HTTP/1.1 400 Could not make a dog.");
echo json_encode(array('errorMessage' => 'Unexpected error: ' . $mEx->getMessage()));
exit;
}
}

echo json_encode($dog->toArray());
}

/**
* CRUD - Update
*/
public function changeDogs()
{
$inputDogId = Input::build('Number', 'dogId')
->addRule('min', 1)
->addRule('isInt');
$inputDogName = Input::build('Text', 'dogName')
->addRule('minLength', 3)
->addRule('maxLength', 12);
$inputDogAge = Input::build('Number', 'dogAge')
->addRule('min', 0)
->addRule('max', 100)
->addRule('isInt');
$inputDogBreed = Input::build('Select', 'dogBreed')
->addRule('availableOptions', array(
'germanSheppard',
'siberianHusky',
'biggles',
'borderCollie'
));

try {
$inputDogId->validate();
$inputDogName->validate();
$inputDogAge->validate();
$inputDogBreed->validate();

$dog = new Dog();
$dog->find(array('id' => $inputDogId->getValue()));
$dog->name = $inputDogName->getValue();
$dog->age = $inputDogAge->getValue();
$dog->breed = $inputDogBreed->getValue();
$dog->save();

} catch (RuleException $rEx) {
header("HTTP/1.1 400 Could not change a dog.");
echo json_encode(array('errorMessage' => $rEx->getMessage()));
} catch (ModelException $mEx) {
switch ($mEx->getCode()) {
case Dog::ERR_RECORDS_FOUND:
header("HTTP/1.1 400 Dog does not exist.");
echo json_encode(array('errorMessage' => 'Dog you are trying to change does not exist.'));
exit;
break;
default:
header("HTTP/1.1 400 Could not change a dog.");
echo json_encode(array('errorMessage' => 'Unexpected error: ' . $mEx->getMessage()));
exit;
}
}
}

/**
* CRUD - Delete
*/
public function dogMassacre()
{
$inputDogId = Input::build('Number', 'dogId')
->addRule('min', 1)
->addRule('isInt');

try {
$inputDogId->validate();

$dog = new Dog();
$dog->find(array('id' => $inputDogId->getValue()));
$dog->delete();

} catch (RuleException $rEx) {
header("HTTP/1.1 400 Could not delete a dog.");
echo json_encode(array('errorMessage' => $rEx->getMessage()));
} catch (ModelException $mEx) {
switch ($mEx->getCode()) {
case Dog::ERR_RECORDS_FOUND:
header("HTTP/1.1 400 Dog does not exist.");
echo json_encode(array('errorMessage' => 'Dog you are trying to delete does not exist.'));
exit;
break;
default:
header("HTTP/1.1 400 Could not delete a dog.");
echo json_encode(array('errorMessage' => 'Unexpected error: ' . $mEx->getMessage()));
exit;
}
}
}
}
29 changes: 0 additions & 29 deletions application/engine/Database.php

This file was deleted.

23 changes: 0 additions & 23 deletions application/engine/Model.php

This file was deleted.

Loading

0 comments on commit 40005e0

Please sign in to comment.