nahanil Posted December 2, 2016 Report Posted December 2, 2016 (edited) Hey all, Just wondering if there's a Right Way™ to access the systemEncrypt/systemDecrypt methods from within a module (specifically, a forked version of the Plesk service module). I've hacked it in for now, but it feels dirty and though it works I was wondering if there's a better way. Current 'solution': /** * Wrapper around systemEncrypt function * * @param string $string The string to encrypt * @return string The encrypted version of input string */ protected function encryptString($string) { if (!isset($this->Clients)) Loader::loadModels($this, array("Clients")); return $this->Clients->systemEncrypt($string); } /** * Wrapper around systemDecrypt function * * @param string $string The string to decrypt * @return string The decrypted version of input string */ protected function decryptString($string) { if (!isset($this->Clients)) Loader::loadModels($this, array("Clients")); return $this->Clients->systemDecrypt($string); } I don't actually use the Clients model anywhere, just load it so that I can have access to the systemEncrypt/systemDecrypt methods that are attached. I suppose the real question would be is it possible to add a bonafide custom Model to a module, as I'm storing the encrypted values in a table the module is creating for itself during install/upgrade. ie public function upgrade($current_version) { if (version_compare($this->getVersion(), $current_version, ">")) { // Upgrade to v1.0.2 if (version_compare($current_version, "0.2.3", "<")) { $this->Record-> setField("id", array('type' => "int",'size' => 10,'unsigned' => true,'auto_increment' => true))-> setField("client_id", array('type' => "int", 'size' => 10))-> setField("encrypted_field", array('type' => "varchar", 'size' => 255))-> ... setKey(array("id"), "primary")-> ... create("my_custom_table"); } } } $some_data = $this->Record->select()->from("my_custom_table") ->where("client_id", "=", $service->client_id) ->fetch(); $some_data->encrypted_field = $this->decryptString($some_data->encrypted_field); Not sure how I could wrap this up and have $this->MyModel->foo(), but I assume if it's possible it'd extend some base model class which would give me the encryption methods 'For Free'. Edited December 2, 2016 by texh Added more of my example code to hopefully clarify what I'm doing/what I'd like to do Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.