Ejemplo n.º 1
0
 /**
  * Tests build()
  * 
  * @param string $type Validation type
  * @see ValidatorFactory::build()
  * @dataProvider provideTestBuild
  */
 public function testBuild($type)
 {
     $bav = new BAV();
     $bank = new Bank($bav->getDataBackend(), null, $type);
     $validator = $this->factory->build($bank);
     $this->assertInstanceOf("\\malkusch\\bav\\Validator{$type}", $validator);
 }
Ejemplo n.º 2
0
 /**
  * @return ValidatorFactory
  */
 public static function getInstance()
 {
     if (ValidatorFactory::$_instance == null) {
         ValidatorFactory::$_instance = new ValidatorFactory();
     }
     return ValidatorFactory::$_instance;
 }
 public function execute()
 {
     //SESSION
     $session = SessionFactory::create();
     $date = $session->get("selected-date");
     //VALIDATION
     $validator = ValidatorFactory::create();
     $validator->ifTrue($date == null)->respond(INCOMPLETE_FILTER_DATA);
     //SESSION DATA
     $sessionData = array('date' => $date);
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $pageNumber = $params->get('page-number');
     $rowsPerPage = $params->get('rows-per-page');
     //PAGINATOR
     $paginator = PaginatorFactory::create();
     $paginator->pageNumber = $pageNumber;
     $datahandler = DatahandlerFactory::create('D_ClientRequestsRowsTotalNumber');
     $datahandler->setInData($sessionData);
     $rowsTotalNumber = $datahandler->getOutData();
     //Always force a single page
     $paginator->rowsPerPage = $rowsTotalNumber;
     //DATAHANDLERS
     $datahandler = DatahandlerFactory::create('D_FrequencyTableOfClientRequests');
     $datahandler->setInData($sessionData);
     $data = $datahandler->getOutData();
     //VALIDATION
     $validator->ifTrue($data == array())->respond('No activity for the day: ' . $date);
     //PAGINATOR
     $paginator->rowsTotalNumber = $rowsTotalNumber;
     //VIEW
     $view = ViewFactory::create('V_FrequencyTableOfClientRequests');
     $view->setInData($data);
     $view->display();
 }
Ejemplo n.º 4
0
 function __construct(RouteCollection $routes, MatcherInterface $matcher, GeneratorInterface $generator = null, RequestContext $context)
 {
     $this->_routes = $routes;
     $this->_matcher = $matcher;
     $this->_matcher->getValidators()->merge(ValidatorFactory::getDefaultValidators());
     $this->_generator = $generator;
     $this->_context = $context;
     $this->_matcher->setContext($context);
     $this->_generator->setContext($context);
 }
Ejemplo n.º 5
0
 /**
  * @param string $name
  * @param string  $value
  * @param bool   $stopOnError
  *
  * @return bool
  */
 public function validate($name, $value, $stopOnError = false)
 {
     $this->errors = [];
     if (null === $this->validator) {
         $this->validator = ValidatorFactory::create($name, $this->type, $this->rules);
     }
     $isValid = $this->validator->validate($value, $stopOnError);
     if (false === $isValid) {
         $this->errors = $this->validator->getErrors();
     }
     return $isValid;
 }
 public function execute()
 {
     $params = RequestParametersFactory::create();
     $id = $params->get('user-id');
     $validator = ValidatorFactory::create();
     $validator->ifTrue($id == "1")->respond(NOT_DELETE_ADMIN);
     $session = SessionFactory::create();
     $session->set('user-id', $id);
     $datahandler = DatahandlerFactory::create('D_ReadUserById');
     $datahandler->setInData($id);
     $data = $datahandler->getOutData();
     $view = ViewFactory::create('V_DeleteUserConfirmation');
     $view->setInData($data);
     $view->display();
     unset($datahandler, $view);
 }
Ejemplo n.º 7
0
 public function execute()
 {
     //SESSION
     $session = SessionFactory::create();
     if ($session->get("authenticated") == null) {
         $session->set("authenticated", false);
     }
     if ($session->get("authorized") == null) {
         $session->set("authorized", false);
     }
     //ACTIONS
     $actions = ActionFactory::create();
     //REQUESTHANDLER AND SELECTACTIONKEY
     $requestHandler = RequestHandlerFactory::create();
     $selectedActionKey = $requestHandler->getSelectedActionKey();
     //VALIDATOR
     $validator = ValidatorFactory::create();
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     ////LOGICA DE AUTENTICACIÓN Y AUTORIZACIÓN:
     //Si no está autenticado se ejecuta la acción de autenticación
     //, esto podría ser también si selecciona Authenticate
     $validator->ifFalse($session->get("authenticated"))->execute($actions['A_Authenticate']);
     //Si selecciona Logout Action se le permite ejecutar siempre.
     $validator->ifTrue($selectedActionKey == 'A_Logout')->execute($actions['A_Logout']);
     //Si después de ser autenticado entra aquí no está autenticado
     //se ejecuta Logout:
     $validator->ifFalse($session->get("authenticated"))->execute($actions['A_Logout']);
     //Si está autenticado y no autorizado se ejecuta la acción de autorización
     //(siempre se debe autorizar, para que esto sea más eficiente armar un cache en
     //session con las acciones autorizadas)
     $actions['A_Authorize']->execute();
     //Si está autenticado y no autorizado:
     // $validator->ifFalse( $authorizer->isAuthorized() )
     $validator->ifFalse($session->get("authorized"))->respond(NO_AUTHORIZED_ACTION);
     /*Si está autenticado y autorizado y quiere ejecutar login lo 
     		redirijo a default a default action:*/
     $validator->ifTrue($selectedActionKey == "A_Authenticate")->redirectTo('index.php?A_EnterFilterDataForm');
     //Si está autenticado y autorizado y ejecuta una acción no existente
     $validator->ifFalse(array_key_exists($selectedActionKey, $actions))->respond($selectedActionKey . " " . NOT_IMPLEMENTED);
     //Si está autenticado y autorizado y ejecuta una acción existente
     $actions[$selectedActionKey]->execute();
 }
 public function execute()
 {
     //SESSION
     $session = SessionFactory::create();
     $date = $session->get("selected-date");
     //VALIDATION
     $validator = ValidatorFactory::create();
     $validator->ifTrue($date == null)->respond(INCOMPLETE_FILTER_DATA);
     //SESSION DATA
     $sessionData = array('date' => $date);
     //DATAHANDLER
     $datahandler = DatahandlerFactory::create('D_ClientRequestVerticalBarPlot');
     $datahandler->setInData($sessionData);
     $data = $datahandler->getOutData();
     //VALIDATION
     $validator->ifTrue($data == array())->respond('No activity for the day: ' . $date);
     //VIEW
     $view = ViewFactory::create('V_ClientRequestVerticalBarPlot');
     $view->setInData($data);
     $view->display();
 }
 public function execute()
 {
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $params->get('role-name');
     $description = $params->get('role-description');
     //FILTERS
     $filter = FilterFactory::create();
     $filteredName = $filter->filters($name);
     //VALIDATOR//VALIDO QUE EL ROLE YA NO EXISTA
     $datahandler = DatahandlerFactory::create();
     $datahandler['D_ReadRoleByName']->setInData($filteredName);
     $existingRole = $datahandler['D_ReadRoleByName']->getOutData();
     $validator = ValidatorFactory::create();
     $validator->ifFalse($existingRole['name'] == null)->respond(EXISTING_ROLE);
     //DATAHANDLER
     $datahandler['D_CreateRole']->setInData(array("name" => "{$name}", "description" => "{$description}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadRolesPaginated');
 }
 public function execute()
 {
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $params->get('role-name');
     $description = $params->get('role-description');
     $session = SessionFactory::create();
     $id = $session->get('role-id');
     //FILTERS
     $filter = FilterFactory::create();
     $filteredName = $filter->filters($name);
     $filteredDescription = $filter->filters($description);
     //VALIDATOR
     $validator = ValidatorFactory::create();
     //DATASET
     $datahandler = DatahandlerFactory::create('D_UpdateRole');
     $datahandler->setInData(array("id" => "{$id}", "name" => "{$filteredName}", "description" => "{$filteredDescription}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadRolesPaginated');
 }
 public function execute()
 {
     //SESSION
     $session = SessionFactory::create();
     $clientIp = $session->get("selected-client-ip");
     $date = $session->get("selected-date");
     //VALIDATION
     $validator = ValidatorFactory::create();
     $validator->ifTrue($clientIp == null or $date == null)->respond(INCOMPLETE_FILTER_DATA);
     //SESSION DATA
     $sessionData = array('client-ip' => $clientIp, 'date' => $date);
     //DATAHANDLER
     $datahandler = DatahandlerFactory::create('D_ClientDataLineChart');
     $datahandler->setInData($sessionData);
     $data = $datahandler->getOutData();
     //VALIDATION
     $validator->ifTrue($data == array())->respond('Client: ' . $clientIp . ' no activity in the day: ' . $date);
     //VIEW
     $view = ViewFactory::create('V_ClientDataLineChart');
     $view->setInData($data);
     $view->display();
 }
 public function execute()
 {
     //FILTERS
     $filter = FilterFactory::create();
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $filter->filters($params->get('user-name'));
     $password = $params->get('user-password');
     $passwordConfirmation = $params->get('password-confirmation');
     $encryptPassword = crypt($password);
     //VALIDATION
     $datahandler = DatahandlerFactory::create();
     $datahandler['D_ReadUserByName']->setInData($name);
     $data = $datahandler['D_ReadUserByName']->getOutData();
     $validator = ValidatorFactory::create();
     $validator->ifTrue($data['name'] != null)->respond(EXISTING_USER);
     $validator->ifFalse($password == $passwordConfirmation)->respond(PASSWORDS_NOT_MATCH);
     //DATAHANDLER
     $datahandler['D_CreateUser']->setInData(array("name" => "{$name}", "password" => "{$encryptPassword}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadUsersPaginated');
 }
 public function execute()
 {
     //PARAMETERS
     $params = RequestParametersFactory::create();
     $name = $params->get('user-name');
     $password = $params->get('user-password');
     $passwordConfirmation = $params->get('password-confirmation');
     $encryptPassword = crypt($password);
     $session = SessionFactory::create();
     $id = $session->get('user-id');
     //FILTERS
     $filter = FilterFactory::create();
     $filter->filters($name);
     //VALIDATOR
     $validator = ValidatorFactory::create();
     $validator->ifFalse($password == $passwordConfirmation)->respond(PASSWORDS_NOT_MATCH);
     //DATASET
     $datahandler = DatahandlerFactory::create('D_UpdateUser');
     $datahandler->setInData(array("id" => "{$id}", "name" => "{$name}", "password" => "{$encryptPassword}"));
     //REDIRECTOR
     $redirector = RedirectorFactory::create();
     $redirector->redirectTo('index.php?A_ReadUsersPaginated');
 }
Ejemplo n.º 14
0
Archivo: Bank.php Proyecto: bmdevel/bav
 /**
  * @return Validator
  */
 public function getValidator()
 {
     if (is_null($this->validator)) {
         $factory = new ValidatorFactory();
         $this->validator = $factory->build($this);
     }
     return $this->validator;
 }
Ejemplo n.º 15
0
 private function parseValidator(\DOMNode $parentNode, Control $control)
 {
     $validators = $parentNode->getElementsByTagName('validator');
     for ($i = 0; $i < $validators->length; $i++) {
         $node = $validators->item($i);
         $type = $node->attributes->getNamedItem('type')->value;
         $validator = ValidatorFactory::createValidator($type);
         $validator->parse($node);
         $control->addValidator($validator);
     }
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = new ValidatorFactory();
     $this->emailObj = $this->object->create('EmailValidator');
 }