/** * Renseigne le gestionnaire d'erreur * @param \Origami\Entity\Manager\Config $config * @return boolean */ private function setConfig(\Origami\Entity\Manager\Config &$config) { // Configuration des associations $associations = $config->getAssociation(); // Si il y a pas de champ a valider if (empty($associations)) { return FALSE; } // Si il y a des champ a valider foreach ($associations as $association) { $this->associations[$association['association_key']] = new \Origami\Entity\Shema\Association($association); } }
/** * Renseigne le gestionnaire d'erreur * @param \Origami\Entity\Manager\Config $config * @return boolean */ private function setConfig(\Origami\Entity\Manager\Config &$config) { // Tableau des champs a valider $validations = $config->getValidation(); // Si il y a pas de champs a valider if (empty($validations)) { return FALSE; } // Si il y a des champs a valider foreach ($validations as $validation) { $this->validations[$validation['field']] = new \Origami\Entity\Shema\Validation($validation); } }
/** * Requête d'écruture */ private function write() { // Liste des champs modifiés $fields = $this->_storage->get(NULL, TRUE); // Si il y a des champs modifiés if (!empty($fields)) { // Si le cryptage est activé et si il y a un champ vecteur if ($this->_config->getOrigami('encryption_enable') && $this->_storage->get('vector') !== FALSE) { // Récupération du champ vecteur $vector = $this->_storage->get('vector'); $value = $vector->getValue(); // Si le vecteur n'a pas de valeur if (empty($value)) { // Créer un vecteur $this->_storage->set('vector', random_string('unique')); // Recharge l'object le vecteur $vector = $this->_storage->get('vector'); // Prépare l'insertion vecteur $this->db()->set($vector->getName(), $vector->getValue(), TRUE); } } // Parcours les champs modifiés foreach ($fields as $field) { // Si le cryptage est activé et qu'il y a des champs crypté if ($this->_config->getOrigami('encryption_enable') && $field->getEncrypt()) { // Récupération du champ vecteur $vector = $this->_storage->get('vector'); // Encryptage de la valeur $this->db()->set("`{$field->getName()}`", "TO_BASE64(AES_ENCRYPT('{$this->db()->escape_str($field->getValue())}', UNHEX('{$this->_config->getOrigami('encryption_key')}'), UNHEX('{$vector->getValue()}')))", FALSE); // Si le champ est un binaire } else { if ($this->_config->getOrigami('binary_enable') && $field->getBinary()) { // Transformation de la valeur $this->db()->set("`{$field->getName()}`", "FROM_BASE64('{$this->db()->escape_str($field->getValue())}')", FALSE); // Si c'est un champ normal } else { $this->db()->set($field->getName(), $field->getValue(), TRUE); } } } } return $this->db(); }
/** * Modifie le nom de la clé primaire * @param \Origami\Entity\Manager\Config $config */ public function setName(\Origami\Entity\Manager\Config &$config) { $this->name = $config->getPrimaryKey(); }
/** * Renseigne le gestionnaire d'erreur * @param \Origami\Entity\Manager\Config $config */ private function setConfig(\Origami\Entity\Manager\Config &$config) { foreach ($config->getField() as $field) { $this->fields[$field['name']] = new \Origami\Entity\Shema\Field($field, NULL, TRUE); } }
/** * Efface un ou plusieurs modèle * @return boolean */ public function delete() { return \Origami\DB::get($this->config->getDataBase())->delete($this->config->getTable()); }