Exemplo n.º 1
0
Arquivo: Db.php Projeto: rj28/test
 /**
  * @param $param1 AdapterInterface|Closure
  * @param $param2 Closure|null
  *
  * @throws Exception
  * @return mixed
  */
 public static function transaction()
 {
     switch (func_num_args()) {
         case 1:
             $db = DI::getDefault()['db'];
             $callback = func_get_arg(0);
             break;
         case 2:
             $db = func_get_arg(0);
             $callback = func_get_arg(1);
             break;
         default:
             throw new Exception("Bad parameter count");
     }
     /** @var $db       AdapterInterface */
     /** @var $callback Closure          */
     //Assert::true($db instanceof AdapterInterface);
     Assert::true($callback instanceof Closure);
     $db->begin();
     try {
         $ret = $callback($db);
         $db->commit();
         return $ret;
     } catch (Exception $e) {
         $db->rollback();
         throw $e;
     }
 }
Exemplo n.º 2
0
 public function crud_initialize()
 {
     if ($id = (int) $this->dispatcher->getParam('id', 'uint')) {
         $model = $this->crud_getModel();
         Assert::true($this->_crud_model = $model::findFirst($id));
     }
 }
Exemplo n.º 3
0
 public static function test()
 {
     if (file_exists(self::_getTableDataFileName())) {
         Assert::true(is_writeable(self::_getTableDataFileName()));
     } else {
         Assert::true(is_writeable(dirname(self::_getTableDataFileName())));
     }
 }
Exemplo n.º 4
0
 /**
  * Executes the validation
  *
  * @param \Phalcon\Validation $validation
  * @param string $field
  * @return boolean
  */
 public function validate($validator, $attribute)
 {
     Assert::true($modelName = $this->getOption('model'));
     Assert::true($fieldName = $this->getOption('field') ?: $attribute);
     $model = $modelName::findFirst(["{$fieldName} = ?0", 'bind' => [$validator->getValue($attribute)]]);
     if ($model) {
         $message = $this->getOption('message') ?: "Field '{$attribute}' is not unique";
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
 }
Exemplo n.º 5
0
 public function indexAction()
 {
     $this->view->noRender();
     Assert::found($query = $this->dispatcher->getParam('query'));
     Assert::found($pkg = $this->getPackage($query));
     $dst = DOCROOT . '/../public/media/';
     @Helper::mkdir($dst . dirname($query), 0777);
     Assert::found($f = fopen('zip://' . $pkg . '#' . $query, 'r'));
     Assert::true($d = fopen($dst . $query, 'w'));
     $content = '';
     while (!feof($f)) {
         $content .= $data = fread($f, 8 * 1024);
         fwrite($d, $data);
     }
     fclose($f);
     $mime = null;
     if ($ext = strtolower(pathinfo($query, PATHINFO_EXTENSION))) {
         $mime = empty(FileInfo::$types[$ext]) ? null : FileInfo::$types[$ext];
     }
     if ($mime) {
         $this->response->setHeader('Content-Type', $mime);
     }
     return $this->response->setContent($content);
 }
Exemplo n.º 6
0
Arquivo: Assert.php Projeto: rj28/test
 public static function post(RequestInterface $request, $message = "Only POST requests allowed")
 {
     Assert::true($request->isPost(), $message);
 }
Exemplo n.º 7
0
Arquivo: Helper.php Projeto: rj28/test
 public static function fileDownload($url, $fileName)
 {
     try {
         Assert::true($f = fopen($url, 'r'));
         Assert::true($fd = fopen($fileName, 'w+'));
         while (!feof($f)) {
             fwrite($fd, fread($f, 8 * 1024));
         }
         fclose($f);
         fclose($fd);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }