Example #1
0
 public function totalAction()
 {
     if (!$this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->setStatusCode(401);
         return false;
     }
     $post = $this->getRequest()->getPost();
     $validator = new \Zend\I18n\Validator\IsInt();
     if ($validator->isValid($post['venda_id'])) {
         $service = $this->getServiceLocator()->get('TotalizaVendaService');
         $result = $service->fetchTotalizaByVenda($post['venda_id'])->toArray();
         if (!empty($result)) {
             $entity = new VendaTotalEntity();
             $entity->setVendaId($result[0]['venda_id']);
             $entity->setTotal($result[0]['total']);
             $entity->setImposto($result[0]['imposto']);
             $service = $this->getServiceLocator()->get('VendaTotalMapper');
             $service->save($entity);
             return new \Zend\View\Model\JsonModel($result[0]);
         }
     }
     $this->getResponse()->setStatusCode(401);
     return false;
 }
Example #2
0
 /**
  * Call
  */
 public function call()
 {
     //print_r('MiddlewareTest middleware call method------');
     //print_r($this->next);
     //Read flash messaging from previous request if available
     //$this->loadMessages();
     //Prepare flash messaging for current request
     //$env = $this->app->environment();
     //$env['slim.flash'] = $this;
     // Create a validator chain and add validators to it
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attach(new \Zend\Validator\StringLength(array('min' => 6, 'max' => 12)))->attach(new \Zend\I18n\Validator\Alnum());
     // Validate the username
     if ($validatorChain->isValid("testteeewwwwwwwwwwwww__")) {
         // username passed validation
     } else {
         // username failed validation; print reasons
         /* foreach ($validatorChain->getMessages() as $message) {
                echo "$message\n";
            }*/
         //$this->app->redirect('/error');
         //$this->app->error();
         //$this->app->halt(500, "info status test!!!!");
         /*$this->app->contentType('application/json');
           $this->app->halt(500, '{"error":"Something went wrong"}');
           $this->app->stop();*/
         //exit();
         //$this->app->run();
         /*$response = $this->app->response();
         
                     //Generate Response headers
                     $response->header('Content-Type', "application/json");
                     $response->status(DEFAULT_RESPONSE_CODE);                  
                     $response->header('Content-Length', '500');
         
                     $responseBody = array('message'=> $message);
                     $response->body(json_encode($responseBody));
         
         
                     $response->send();*/
         //ob_clean();
         $publicHash = '3441df0babc2a2dda551d7cd39fb235bc4e09cd1e4556bf261bb49188f548348';
         $privateHash = 'e249c439ed7697df2a4b045d97d4b9b7e1854c3ff8dd668c779013653913572e';
         $content = json_encode(array('test' => 'content'));
         //$this->app->setPublicHash('3441df0babc2a2dda551d7cd39fb235bc4e09cd1e4556bf261bb49188f548348');
         //
         //print_r("------public hash---------".$this->app->getPublicHash()."------public hash---------");
         /*$hash = hash_hmac('sha256', $content, $privateHash);
         
                     $headers = array(
                         'X-Public: '.$publicHash,
                         'X-Hash: '.$hash
                     );
                     //ob_flush();
                     
                     
                     $ch = curl_init('http://localhost/slim_redirect_test/index.php/redirected_path');
                     curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
                     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
                     curl_setopt($ch,CURLOPT_POSTFIELDS,$content);
         
                     $result = curl_exec($ch);
                     curl_close($ch);*/
         //ob_end_flush();
         /*ob_end_clean();
           $newURL = 'http://localhost/slim_redirect_test/index.php/redirected_path';
           header("Location: {$newURL}");*/
     }
     $validator = new \Zend\Validator\Barcode('EAN13');
     $floatValidator = new \Zend\I18n\Validator\IsFloat();
     if ($floatValidator->isValid(5.3)) {
         //print_r ("--float test edildi onaylandı---");
         $intValidator = new \Zend\I18n\Validator\IsInt();
     }
     $intValidator->setMessage("test validation");
     if ($intValidator->isValid(5)) {
         //print_r ("--int test edildi onaylandı---");
         $validator = new \Zend\Validator\StringLength();
     }
     $validator->setMax(6);
     $validator->isValid("Test");
     // returns true
     $validator->isValid("Testing");
     // returns false
     /*print_r($validator->isValid("Test"));
       print_r("fffffffffffffffffffff----    ");
       print_r($validator->isValid("Testing"));*/
     if (!$validator->isValid("Testing")) {
         //print_r("---is not valid----");
         $logger = new \Zend\Log\Logger();
     }
     $writer = new \Zend\Log\Writer\Stream('php://output');
     /*$logger->addWriter($writer);
       $logger->log(\Zend\Log\Logger::INFO, 'Informational message');
       $this->app->log->debug("test loggg");*/
     $this->next->call();
     //$this->save();
 }