/** * Validates the form. * * @param array $data Data to validate. * @param bool $skipEntityCreation Skip entity creation. * * @return boolean */ public function isValid($data = null, $skipEntityCreation = false) { if (!$data) { $data = $this->getDI()->getRequest()->getPost(); } if (isset($data['adapter']) && $data['adapter'] == '0') { if (empty($data['cacheDir']) || !is_dir($data['cacheDir'])) { $this->addError('Files location isn\'t correct!'); return false; } } return parent::isValid($data, $skipEntityCreation); }
/** * Check form validation and transform image if valid. * * @param array|null $data Form data. * @param bool $skipEntityCreation Skip entity creation. * * @throws \Engine\Exception * @return bool */ public function isValid($data = null, $skipEntityCreation = false) { $isValid = parent::isValid($data, $skipEntityCreation); if ($isValid) { foreach ($this->_transformations as $field => $transform) { $file = $this->getFiles($field); if (!$file) { continue; } $adapterClass = 'Phalcon\\Image\\Adapter\\' . $transform['adapter']; unset($transform['adapter']); if (!class_exists($adapterClass)) { throw new Exception(sprintf('Image adapter "%s" does not exists.', $adapterClass)); } $adapter = new $adapterClass($file->getTempName()); foreach ($transform as $option => $values) { if (!is_array($values)) { $values = [$values]; } call_user_func_array([$adapter, $option], $values); } $fileName = $file->getTempName() . '.' . pathinfo($file->getName(), PATHINFO_EXTENSION); if (!$adapter->save($fileName)) { $this->getDI()->getLogger()->error(sprintf('Can not transform image. Form: "%s", Field: "%s".', get_class($this), $field)); } else { rename($fileName, $file->getTempName()); } } } return $isValid; }
/** * Validates the form. * * @param array $data Data to validate. * @param bool $skipEntityCreation Skip entity creation. * * @return boolean */ public function isValid($data = null, $skipEntityCreation = true) { if (!$data) { $data = $this->getDI()->getRequest()->getPost(); } // Check package location. $packageManager = new Manager(); $path = $packageManager->getPackageLocation($data['type']); if (!is_writable($path)) { $this->addError('Can not create package. Package location isn\'t writable: ' . $path); $this->setValues($data); return false; } // Also check that config file is writable. if (!is_writable(ROOT_PATH . Config::CONFIG_PATH)) { $this->addError('Configuration file isn\'t writable...'); $this->setValues($data); return false; } if (isset($data['type']) && $data['type'] == 'widget' && !$this->hasEntity('widget')) { $this->addEntity(new WidgetModel(), 'widget'); } if (!parent::isValid($data, $skipEntityCreation)) { return false; } // Check package existence. $id = $this->getEntity()->id; $condition = "type='{$data['type']}' AND name='{$data['name']}'" . ($id ? " AND id!='{$id}'" : ''); if (Package::findFirst($condition)) { $this->addError('Package with that name already exist!'); return false; } // Check widget existence. if ($this->hasEntity('widget')) { $name = ucfirst($data['name']); $id = $this->getEntity('widget')->id; $condition = "module='{$data['module']}' AND name='{$name}'" . ($id ? " AND id!='{$id}'" : ''); if (WidgetModel::findFirst($condition)) { $this->addError('Widget with that name already exist!'); return false; } } return true; }