diff --git a/Library/Phalcon/Legacy/Crypt.php b/Library/Phalcon/Legacy/Crypt.php deleted file mode 100644 index 4dd465779..000000000 --- a/Library/Phalcon/Legacy/Crypt.php +++ /dev/null @@ -1,546 +0,0 @@ - | - | Eduar Carvajal | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Legacy; - -use Phalcon\Legacy\Crypt\Exception; - -/** - * Phalcon\Legacy\Crypt - * - * Port of Phalcon 2.0.x Phalcon\Crypt. - * Provides encryption facilities to phalcon applications. - * - * - * $crypt = new \Phalcon\Legacy\Crypt(); - * - * $key = 'le password'; - * $text = 'This is a secret text'; - * - * $encrypted = $crypt->encrypt($text, $key); - * - * echo $crypt->decrypt($encrypted, $key); - * - * - * @link https://github.com/phalcon/incubator/issues/563 - * @package Phalcon\Legacy - */ -class Crypt implements CryptInterface -{ - protected $key; - - protected $padding = 0; - - protected $mode = MCRYPT_MODE_CBC; - - protected $cipher = "rijndael-256"; - - const PADDING_DEFAULT = 0; - - const PADDING_ANSI_X_923 = 1; - - const PADDING_PKCS7 = 2; - - const PADDING_ISO_10126 = 3; - - const PADDING_ISO_IEC_7816_4 = 4; - - const PADDING_ZERO = 5; - - const PADDING_SPACE = 6; - - /** - * Changes the padding scheme used - * - * @param int $scheme - * @return CryptInterface - */ - public function setPadding($scheme) - { - $this->padding = $scheme; - - return $this; - } - - /** - * @inheritdoc - * - * @param string $cipher - * @return CryptInterface - */ - public function setCipher($cipher) - { - $this->cipher = $cipher; - - return $this; - } - - /** - * Returns the current cipher - * - * @return string - */ - public function getCipher() - { - return $this->cipher; - } - - /** - * Sets the encrypt/decrypt mode - * - * @param string $mode - * @return CryptInterface - */ - public function setMode($mode) - { - $this->mode = $mode; - - return $this; - } - - /** - * Returns the current encryption mode - * - * @return string - */ - public function getMode() - { - return $this->mode; - } - - /** - * Sets the encryption key - * - * @param string $key - * @return CryptInterface - */ - public function setKey($key) - { - $this->key = $key; - - return $this; - } - - /** - * Returns the encryption key - * - * @return string - */ - public function getKey() - { - return $this->key; - } - - /** - * Pads texts before encryption - * - * @link http://www.di-mgt.com.au/cryptopad.html - * - * @param string $text - * @param string $mode - * @param int $blockSize - * @param int $paddingType - * @return string - * @throws Exception - */ - protected function cryptPadText($text, $mode, $blockSize, $paddingType) - { - $paddingSize = 0; - $padding = null; - - if ($mode == MCRYPT_MODE_CBC || $mode == MCRYPT_MODE_ECB) { - $paddingSize = $blockSize - (strlen($text) % $blockSize); - - if ($paddingSize >= 256) { - throw new Exception("Block size is bigger than 256"); - } - - switch ($paddingType) { - case self::PADDING_ANSI_X_923: - $padding = str_repeat(chr(0), $paddingSize - 1) . chr($paddingSize); - - break; - - case self::PADDING_PKCS7: - $padding = str_repeat( - chr($paddingSize), - $paddingSize - ); - - break; - - case self::PADDING_ISO_10126: - $padding = ""; - - foreach (range(0, $paddingSize - 2) as $i) { - $padding .= chr( - rand() - ); - } - - $padding .= chr($paddingSize); - - break; - - case self::PADDING_ISO_IEC_7816_4: - $padding = chr(0x80) . str_repeat(chr(0), $paddingSize - 1); - - break; - - case self::PADDING_ZERO: - $padding = str_repeat( - chr(0), - $paddingSize - ); - - break; - - case self::PADDING_SPACE: - $padding = str_repeat(" ", $paddingSize); - - break; - - default: - $paddingSize = 0; - - break; - } - } - - if (!$paddingSize) { - return $text; - } - - if ($paddingSize > $blockSize) { - throw new Exception("Invalid padding size"); - } - - return $text . substr($padding, 0, $paddingSize); - } - - /** - * Removes $paddingType padding from text - * If the function detects that the text was not padded, it will return it unmodified - * - * @param string $text Message to be unpadded - * @param string $mode Encryption mode; unpadding is applied only in CBC or ECB mode - * @param int $blockSize Cipher block size - * @param int $paddingType Padding scheme - * @return string - */ - protected function cryptUnpadText($text, $mode, $blockSize, $paddingType) - { - $paddingSize = 0; - $length = strlen($text); - - if ($length > 0 && ($length % $blockSize == 0) && ($mode == MCRYPT_MODE_CBC || $mode == MCRYPT_MODE_ECB)) { - switch ($paddingType) { - case self::PADDING_ANSI_X_923: - $last = substr($text, $length - 1, 1); - $ord = (int) ord($last); - - if ($ord <= $blockSize) { - $paddingSize = $ord; - - $padding = str_repeat(chr(0), $paddingSize - 1) . $last; - - if (substr($text, $length - $paddingSize) != $padding) { - $paddingSize = 0; - } - } - - break; - - case self::PADDING_PKCS7: - $last = substr($text, $length - 1, 1); - $ord = (int) ord($last); - - if ($ord <= $blockSize) { - $paddingSize = $ord; - - $padding = str_repeat( - chr($paddingSize), - $paddingSize - ); - - if (substr($text, $length - $paddingSize) != $padding) { - $paddingSize = 0; - } - } - - break; - - case self::PADDING_ISO_10126: - $last = substr($text, $length - 1, 1); - $paddingSize = (int) ord($last); - - break; - - case self::PADDING_ISO_IEC_7816_4: - $i = $length - 1; - - while ($i > 0 && $text[$i] == 0x00 && $paddingSize < $blockSize) { - $paddingSize++; - $i--; - } - - if ($text[$i] == 0x80) { - $paddingSize++; - } else { - $paddingSize = 0; - } - - break; - - case self::PADDING_ZERO: - $i = $length - 1; - - while ($i >= 0 && $text[$i] == 0x00 && $paddingSize <= $blockSize) { - $paddingSize++; - $i--; - } - - break; - - case self::PADDING_SPACE: - $i = $length - 1; - - while ($i >= 0 && $text[$i] == 0x20 && $paddingSize <= $blockSize) { - $paddingSize++; - $i--; - } - - break; - - default: - break; - } - - if ($paddingSize && $paddingSize <= $blockSize) { - if ($paddingSize < $length) { - return substr($text, 0, $length - $paddingSize); - } - - return ""; - } - } - - return $text; - } - - /** - * Encrypts a text - * - * - * $encrypted = $crypt->encrypt("Ultra-secret text", "encrypt password"); - * - * - * @param string $text - * @param mixed $key - * @return string - * @throws Exception - */ - public function encrypt($text, $key = null) - { - if (!function_exists("mcrypt_get_iv_size")) { - throw new Exception("mcrypt extension is required"); - } - - if ($key === null) { - $encryptKey = $this->key; - } else { - $encryptKey = $key; - } - - if (empty($encryptKey)) { - throw new Exception("Encryption key cannot be empty"); - } - - $ivSize = mcrypt_get_iv_size($this->cipher, $this->mode); - if (strlen($encryptKey) > $ivSize) { - throw new Exception("Size of key is too large for this algorithm"); - } - - $iv = strval( - mcrypt_create_iv($ivSize, MCRYPT_RAND) - ); - - $blockSize = intval( - mcrypt_get_block_size($this->cipher, $this->mode) - ); - - if ($this->padding != 0 && ($this->mode == MCRYPT_MODE_CBC || $this->mode == MCRYPT_MODE_ECB)) { - $padded = $this->cryptPadText( - $text, - $this->mode, - $blockSize, - $this->padding - ); - } else { - $padded = $text; - } - - return $iv . mcrypt_encrypt( - $this->cipher, - $encryptKey, - $padded, - $this->mode, - $iv - ); - } - - /** - * Decrypts a text - * - * - * echo $crypt->decrypt($encrypted, "decrypt password"); - * - * - * @param string $text - * @param string $key - * @return string - * @throws Exception - */ - public function decrypt($text, $key = null) - { - if (!function_exists("mcrypt_get_iv_size")) { - throw new Exception("mcrypt extension is required"); - } - - if ($key === null) { - $decryptKey = $this->key; - } else { - $decryptKey = $key; - } - - if (empty($decryptKey)) { - throw new Exception("Decryption key cannot be empty"); - } - - $ivSize = mcrypt_get_iv_size($this->cipher, $this->mode); - $keySize = strlen($decryptKey); - if ($keySize > $ivSize) { - throw new Exception("Size of key is too large for this algorithm"); - } - - if ($keySize > strlen($text)) { - throw new Exception( - "Size of IV is larger than text to decrypt. Are you trying to decrypt an uncrypted text?" - ); - } - - $data = substr($text, $ivSize); - - $decrypted = mcrypt_decrypt( - $this->cipher, - $decryptKey, - $data, - $this->mode, - substr($text, 0, $ivSize) - ); - - $blockSize = mcrypt_get_block_size($this->cipher, $this->mode); - - if ($this->mode == MCRYPT_MODE_CBC || $this->mode == MCRYPT_MODE_ECB) { - return $this->cryptUnpadText( - $decrypted, - $this->mode, - $blockSize, - $this->padding - ); - } - - return $decrypted; - } - - /** - * Encrypts a text returning the result as a base64 string - * - * @param string $text - * @param mixed $key - * @param bool $safe - * @return string - */ - public function encryptBase64($text, $key = null, $safe = false) - { - if ($safe) { - return strtr( - base64_encode( - $this->encrypt($text, $key) - ), - "+/", - "-_" - ); - } - - return base64_encode( - $this->encrypt($text, $key) - ); - } - - /** - * Decrypt a text that is coded as a base64 string - * - * @param string $text - * @param mixed $key - * @param bool $safe - * @return string - */ - public function decryptBase64($text, $key = null, $safe = false) - { - if ($safe) { - return $this->decrypt( - base64_decode( - strtr( - $text, - "-_", - "+/" - ) - ), - $key - ); - } - - return $this->decrypt( - base64_decode($text), - $key - ); - } - - /** - * Returns a list of available cyphers - * - * @return array - */ - public function getAvailableCiphers() - { - return mcrypt_list_algorithms(); - } - - /** - * Returns a list of available modes - * - * @return array - */ - public function getAvailableModes() - { - return mcrypt_list_modes(); - } -} diff --git a/Library/Phalcon/Legacy/Crypt/Exception.php b/Library/Phalcon/Legacy/Crypt/Exception.php deleted file mode 100644 index 64fe616c0..000000000 --- a/Library/Phalcon/Legacy/Crypt/Exception.php +++ /dev/null @@ -1,32 +0,0 @@ - | - | Eduar Carvajal | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Legacy\Crypt; - -/** - * Phalcon\Legacy\Crypt\Exception - * - * Exceptions thrown in Phalcon\Crypt use this class - * - * @package Phalcon\Legacy - */ -class Exception extends \Phalcon\Exception -{ -} diff --git a/Library/Phalcon/Legacy/CryptInterface.php b/Library/Phalcon/Legacy/CryptInterface.php deleted file mode 100644 index 94faf8f9e..000000000 --- a/Library/Phalcon/Legacy/CryptInterface.php +++ /dev/null @@ -1,127 +0,0 @@ - | - | Eduar Carvajal | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Legacy; - -/** - * Phalcon\Legacy\CryptInterface - * - * Interface for Phalcon\Legacy\Crypt - * - * @link https://github.com/phalcon/incubator/issues/563 - * @package Phalcon\Legacy - */ -interface CryptInterface -{ - /** - * Sets the cipher algorithm - * - * @param string $cipher - * @return CryptInterface - */ - public function setCipher($cipher); - - /** - * Returns the current cipher - * - * @return string - */ - public function getCipher(); - - /** - * Sets the encrypt/decrypt mode - * - * @param string $mode - * @return CryptInterface - */ - public function setMode($mode); - - /** - * Returns the current encryption mode - * - * @return string - */ - public function getMode(); - - /** - * Sets the encryption key - * - * @param string $key - * @return CryptInterface - */ - public function setKey($key); - - /** - * Returns the encryption key - * - * @return string - */ - public function getKey(); - - /** - * Encrypts a text - * - * @param string $text - * @param mixed $key - * @return string - */ - public function encrypt($text, $key = null); - - /** - * Decrypts a text - * - * @param string $text - * @param string $key - * @return string - */ - public function decrypt($text, $key = null); - - /** - * Encrypts a text returning the result as a base64 string - * - * @param string $text - * @param mixed $key - * @return string - */ - public function encryptBase64($text, $key = null); - - /** - * Decrypt a text that is coded as a base64 string - * - * @param string $text - * @param mixed $key - * @return string - */ - public function decryptBase64($text, $key = null); - - /** - * Returns a list of available cyphers - * - * @return array - */ - public function getAvailableCiphers(); - - /** - * Returns a list of available modes - * - * @return array - */ - public function getAvailableModes(); -} diff --git a/Library/Phalcon/Logger/Adapter/Database.php b/Library/Phalcon/Logger/Adapter/Database.php deleted file mode 100644 index 2c784849c..000000000 --- a/Library/Phalcon/Logger/Adapter/Database.php +++ /dev/null @@ -1,197 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Logger\Adapter; - -use Phalcon\Logger\Exception; -use Phalcon\Logger\Formatter\FormatterInterface; -use Phalcon\Logger\Item; -use Phalcon\Db\Adapter\AdapterInterface as DbAdapterInterface; -use Phalcon\Logger\Formatter\Line as LineFormatter; -use Phalcon\Db\Column; - -/** - * Phalcon\Logger\Adapter\Database - * - * Adapter to store logs in a database table - */ -class Database extends AbstractAdapter -{ - /** - * Database connection - * - * @var DbAdapterInterface - */ - protected $db; - - /** - * Table name - * - * @var string - */ - protected $table = "log"; - - /** - * Name - * @var string - */ - protected $name = 'phalcon'; - - /** - * @var \Phalcon\Logger\Formatter\AbstractFormatter - */ - protected $_formatter; - - /** - * Adapter options - * @var array - */ - protected $options = []; - - /** - * Constructor. Accepts the name and some options - */ - public function __construct(string $name = 'phalcon', array $options = []) - { - if (!isset($options['db'])) { - throw new Exception("Parameter 'db' is required"); - } - - if (!$options['db'] instanceof DbAdapterInterface) { - throw new Exception( - "Parameter 'db' must be object and implement AdapterInterface" - ); - } - - if (!isset($options['table'])) { - throw new Exception("Parameter 'table' is required"); - } - - $this->db = $options['db']; - $this->table = $options['table']; - - if ($name) { - $this->name = $name; - } - - $this->options = $options; - } - - /** - * Sets database connection - * - * @param DbAdapterInterface $db - * @return $this - */ - public function setDb(DbAdapterInterface $db) - { - $this->db = $db; - - return $this; - } - - /** - * {@inheritdoc} - * - * @return boolean - */ - public function close(): bool - { - if ($this->db->isUnderTransaction()) { - $this->db->commit(); - } - - $this->db->close(); - - return true; - } - - /** - * {@inheritdoc} - * - * @return $this - */ - public function begin(): AdapterInterface - { - $this->db->begin(); - - return $this; - } - - /** - * Commit transaction - * - * @return $this - */ - public function commit(): AdapterInterface - { - $this->db->commit(); - - return $this; - } - - /** - * Rollback transaction - * (happens automatically if commit never reached) - * - * @return $this - */ - public function rollback(): AdapterInterface - { - $this->db->rollback(); - - return $this; - } - - /** - * {@inheritdoc} - * - * @return FormatterInterface - */ - public function getFormatter(): FormatterInterface - { - if (!is_object($this->_formatter)) { - $this->_formatter = new LineFormatter('%message%'); - } - - return $this->_formatter; - } - - /** - * Processes the message i.e. writes it to the file - */ - public function process(Item $item): void - { - $this->db->execute( - 'INSERT INTO ' . $this->table . ' VALUES (null, ?, ?, ?, ?)', - [ - $this->name, - $item->getType(), - $this->getFormatter()->format($item), - $item->getTime(), - ], - [ - Column::BIND_PARAM_STR, - Column::BIND_PARAM_INT, - Column::BIND_PARAM_STR, - Column::BIND_PARAM_INT, - ] - ); - } -} \ No newline at end of file diff --git a/Library/Phalcon/Logger/Adapter/File/Multiple.php b/Library/Phalcon/Logger/Adapter/File/Multiple.php deleted file mode 100644 index dd33b3888..000000000 --- a/Library/Phalcon/Logger/Adapter/File/Multiple.php +++ /dev/null @@ -1,189 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Logger\Adapter\File; - -use Phalcon\Logger\Exception as LoggerException; -use Phalcon\Logger as Logger; -use Phalcon\Logger\Adapter\File as FileLogger; -use Phalcon\Logger\AdapterInterface; - -/** - * Phalcon\Logger\Adapter\File\Multiple - * - * Adapter to save logs into multiple log files based on their level. - * - * TODO Implement transactions. - */ -class Multiple extends FileLogger implements AdapterInterface -{ - /** - * Path to the directory where log files will be saved. No trailing slash. - * - * @var string - */ - protected $path; - - /** - * Adapter options. - * - * @var array - */ - protected $options = []; - - /** - * Class constructor. - * - * @param string $path Directory path for saving the log files. - * @param array $options The following options are available: - * - extension (string) Extension for all log files. - * - prefix (string) Name prefix for all log files - * @throws \Phalcon\Logger\Exception - */ - public function __construct($path, array $options = []) - { - $path = rtrim($path, ' ' . \DIRECTORY_SEPARATOR); - if (!file_exists($path) || !is_dir($path)) { - throw new LoggerException( - 'Directory ' . $path . ' does not exist!' - ); - } - - if (!is_writable($path)) { - throw new LoggerException( - 'Directory ' . $path . ' is not writable!' - ); - } - - $this->path = $path; - - $defaults = [ - 'extension' => 'log', - 'prefix' => '', - ]; - - $this->options = array_merge($defaults, $options); - } - - /** - * Writes the log to the file itself - * - * @param string $message - * @param integer $type - * @param integer $time - * @param array $context - * @throws \Phalcon\Logger\Exception - */ - public function logInternal($message, $type, $time, array $context = []) - { - $filename = $this->path . - \DIRECTORY_SEPARATOR . - $this->options['prefix'] . - $this->getTypeString($type) . - '.' . - $this->options['extension']; - - $log = $this->getFormatter()->format($message, $type, $time, $context); - $result = file_put_contents($filename, $log, \FILE_APPEND); - - if ($result === false) { - throw new LoggerException('Failed to write log into ' . $filename); - } - - return; - } - - /** - * {@inheritdoc} - * - * @throws \Phalcon\Logger\Exception - */ - public function begin() - { - throw new LoggerException( - 'Multiple file logger transactions are not implemented yet!' - ); - } - - /** - * {@inheritdoc} - * - * @throws \Phalcon\Logger\Exception - */ - public function commit() - { - throw new LoggerException( - 'Multiple file logger transactions are not implemented yet!' - ); - } - - /** - * {@inheritdoc} - * - * @throws \Phalcon\Logger\Exception - */ - public function rollback() - { - throw new LoggerException( - 'Multiple file logger transactions are not implemented yet!' - ); - } - - /** - * getTypeString - * - * Translates Phalcon log types into type strings. - * - * TODO: It would be nice to make a config option to say which error levels go into what files. - * - * @param integer $type - * @return string - */ - protected function getTypeString($type) - { - switch ($type) { - case Logger::EMERGENCY: - case Logger::EMERGENCE: - case Logger::CRITICAL: - // emergence, critical - return 'critical'; - - case Logger::ALERT: - case Logger::ERROR: - // error, alert - return 'error'; - - case Logger::WARNING: - // warning - return 'warning'; - - case Logger::NOTICE: - case Logger::INFO: - // info, notice - return 'info'; - - case Logger::DEBUG: - case Logger::CUSTOM: - case Logger::SPECIAL: - default: - // debug, log, custom, special - return 'debug'; - } - } -} diff --git a/Library/Phalcon/Logger/Adapter/Firelogger.php b/Library/Phalcon/Logger/Adapter/Firelogger.php deleted file mode 100644 index 61bd42c84..000000000 --- a/Library/Phalcon/Logger/Adapter/Firelogger.php +++ /dev/null @@ -1,334 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Logger\Adapter; - -use Phalcon\Logger\Formatter\Firelogger as FireloggerFormatter; -use Phalcon\Logger\Adapter as LoggerAdapter; -use Phalcon\Logger\AdapterInterface; - -/** - * Phalcon\Logger\Adapter\Firelogger - * Sends messages to the Firelogger extension in Firefox. - * - * @link http://firelogger.binaryage.com/ - */ -class Firelogger extends LoggerAdapter implements AdapterInterface -{ - /** - * Name - * - * @var string - */ - protected $name = 'phalcon'; - - /** - * Adapter options - * In addition to default options provided by Phalcon\Adapter, you may specify the following: - * (string) password Holds password which the client should send to turn Firelogger on. - * Leave empty if no password authentication is needed. - * (boolean) checkVersion Turn client version checks on / off. - * (boolean) traceable If TRUE, backtraces will be added to all logs. - * - * @var array - */ - protected $options = []; - - /** - * @var boolean - */ - protected $enabled; - - /** - * Holds current Firelogger server version. - * - * @var string - */ - protected $serverVersion = '0.1'; - - /** - * Holds detected Firelogger client version. - * - * @var string - */ - protected $clientVersion; - - /** - * Recommended Firelogger client version. - * - * @var string - */ - protected $recommendedClientVersion = '1.3'; - - /** - * Storage for holding all messages until they are ready to be shipped to client. - * - * @var array - */ - protected $logs = []; - - /** - * Denotes if there is a transaction started. - * - * @var boolean - */ - protected $isTransaction = false; - - /** - * Class constructor. - * - * @param string $name - * @param array $options - */ - public function __construct($name = 'phalcon', array $options = []) - { - $defaults = [ - 'password' => null, - 'checkVersion' => true, - 'traceable' => false, - 'triggerError' => true, - ]; - - if ($name) { - $this->name = $name; - } - - $this->options = array_merge($defaults, $options); - $this->enabled = $this->checkPassword() && $this->checkVersion(); - - register_shutdown_function( - [ - $this, - 'commit', - ] - ); - } - - /** - * Setter for name - * - * @param string $name - * @return $this - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * {@inheritdoc} - * - * @return \Phalcon\Logger\FormatterInterface - */ - public function getFormatter() - { - if (!$this->_formatter) { - $this->_formatter = new FireloggerFormatter($this->name); - } - - return $this->_formatter; - } - - /** - * Writes the log to the headers. - * - * @param mixed $message Stuff to log. Can be of any type castable into a string (i.e. anything except for - * objects without __toString() implementation). - * @param integer $type - * @param integer $time - * @param array $context - */ - public function logInternal($message, $type, $time, $context = []) - { - if (!$this->enabled) { - return; - } - - $trace = null; - - if ($this->options['traceable']) { - $trace = debug_backtrace(); - } - - $log = $this->getFormatter()->format( - $message, - $type, - $time, - $context, - $trace, - count($this->logs) - ); - - $this->logs[] = $log; - - // flush if this is not transaction - if (!$this->isTransaction) { - $this->flush(); - } - } - - /** - * {@inheritdoc} - * - * @return boolean - */ - public function close() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function begin() - { - // flush the previous transaction if there is any - $this->commit(); - - // start a new transaction - $this->isTransaction = true; - } - - /** - * {@inheritdoc} - * Encodes all collected messages into HTTP headers. This method is registered as a shutdown handler, - * so transactions will get committed even if you forget to commit them yourself. - */ - public function commit() - { - if (!$this->isTransaction || empty($this->logs)) { - $this->isTransaction = false; - - return; - } - - $this->flush(); - $this->isTransaction = false; - } - - /** - * {@inheritdoc} - */ - protected function flush() - { - if (headers_sent($file, $line) && $this->options['triggerError']) { - trigger_error( - "Cannot send FireLogger headers after output has been sent" . - ($file ? " (output started at $file:$line)." : "."), - \E_USER_WARNING - ); - - return; - } - - $logs = $this->logs; - - // final encoding - $id = dechex(mt_rand(0, 0xFFFF)) . dechex(mt_rand(0, 0xFFFF)); // mt_rand is not working with 0xFFFFFFFF - $json = json_encode(['logs' => $logs]); - $res = str_split(base64_encode($json), 76); // RFC 2045 - - foreach ($res as $k => $v) { - header("FireLogger-$id-$k:$v"); - } - - $this->logs = []; - } - - /** - * Checks client provided password to see if we should disable/enable the firelogger. - * Disables/enables the firelogger appropriately. - * - * @return boolean - */ - protected function checkPassword() - { - if (!isset($this->options['password'])) { - $this->enabled = true; - - return true; - } - - if (isset($_SERVER['HTTP_X_FIRELOGGERAUTH'])) { - $clientHash = $_SERVER['HTTP_X_FIRELOGGERAUTH']; - - $serverHash = md5( - "#FireLoggerPassword#" . $this->options['password'] . "#" - ); - - if ($clientHash !== $serverHash) { // passwords do not match - $this->enabled = false; - - if ($this->options['triggerError']) { - trigger_error( - "FireLogger passwords do not match. Have you specified correct password FireLogger extension?" - ); - } - } else { - $this->enabled = true; - } - } else { - $this->enabled = false; - } - - return $this->enabled; - } - - /** - * Checks client version vs recommended version and logs a message if there is a mismatch. Does not - * disable firelogger even if there is version mismatch. - * - * @return boolean - */ - private function checkVersion() - { - if (!$this->options['checkVersion']) { - $this->enabled = true; - - return true; - } - - if (!isset($_SERVER['HTTP_X_FIRELOGGER'])) { - $this->enabled = false; - - return false; - } - - $this->clientVersion = $_SERVER['HTTP_X_FIRELOGGER']; - if ($this->clientVersion != $this->recommendedClientVersion) { - error_log( - 'FireLogger for PHP (v' . $this->serverVersion . - ') works best with FireLogger extension of version ' . $this->recommendedClientVersion . - '. You are currently using extension v' . $this->clientVersion . - '. Please install matching versions from http://firelogger.binaryage.com/ and ' . - 'https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Logger' - ); - - $this->enabled = false; - - return false; - } - - $this->enabled = true; - - return true; - } -} diff --git a/Library/Phalcon/Logger/Adapter/Udplogger.php b/Library/Phalcon/Logger/Adapter/Udplogger.php deleted file mode 100644 index 7a1bccecb..000000000 --- a/Library/Phalcon/Logger/Adapter/Udplogger.php +++ /dev/null @@ -1,201 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Logger\Adapter; - -use Phalcon\Logger\Exception; -use Phalcon\Logger\Formatter\Line as LineFormatter; -use Phalcon\Logger\Adapter as LoggerAdapter; -use Phalcon\Logger\AdapterInterface; - -/** - * Phalcon\Logger\Adapter\Udplogger - * Sends messages using UDP protocol to external server - */ -class Udplogger extends LoggerAdapter implements AdapterInterface -{ - /** - * Name - * - * @var string - */ - protected $name = 'phalcon'; - - /** - * Adapter options - * - * @var array - */ - protected $options = []; - - /** - * @var resource - */ - protected $socket; - - /** - * Storage for holding all messages until they are ready to be sent to server. - * - * @var array - */ - protected $logs = []; - - /** - * Flag for the transaction - * - * @var boolean - */ - protected $isTransaction = false; - - /** - * Class constructor. - * - * @param string $name - * @param array $options - * @throws \Phalcon\Logger\Exception - */ - public function __construct($name = 'phalcon', array $options = []) - { - if (!isset($options['url'])) { - throw new Exception("Parameter 'url' is required"); - } - - if (!isset($options['port'])) { - throw new Exception("Parameter 'port' is required"); - } - - if ($name) { - $this->name = $name; - } - - $this->options = $options; - - register_shutdown_function( - [ - $this, - 'commit', - ] - ); - - register_shutdown_function( - [ - $this, - 'close', - ] - ); - } - - /** - * {@inheritdoc} - * - * @return \Phalcon\Logger\FormatterInterface - */ - public function getFormatter() - { - if (!$this->_formatter) { - $this->_formatter = new LineFormatter(); - } - - return $this->_formatter; - } - - /** - * Writes the log. - * - * @param string $message - * @param integer $type - * @param integer $time - * @param array $context - */ - public function logInternal($message, $type, $time, $context = []) - { - $this->logs[] = compact('message', 'type', 'time', 'context'); - - if (!$this->isTransaction) { - $this->send(); - } - } - - /** - * {@inheritdoc} - * - * @return boolean - */ - public function close() - { - if ($this->socket !== null) { - socket_close($this->socket); - } - - return true; - } - - /** - * {@inheritdoc} - */ - public function begin() - { - $this->commit(); - - $this->isTransaction = true; - } - - /** - * {@inheritdoc} - */ - public function commit() - { - if (!$this->isTransaction || empty($this->logs)) { - $this->isTransaction = false; - - return; - } - - $this->send(); - - $this->isTransaction = false; - } - - /** - * {@inheritdoc} - */ - protected function send() - { - if (empty($this->logs)) { - return; - } - - $message = json_encode($this->logs); - - if ($this->socket === null) { - $this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); - } - - socket_sendto( - $this->socket, - $message, - strlen($message), - 0, - $this->options['url'], - $this->options['port'] - ); - - $this->logs = []; - } -} diff --git a/Library/Phalcon/Logger/Formatter/Firelogger.php b/Library/Phalcon/Logger/Formatter/Firelogger.php deleted file mode 100644 index c4eca3f8f..000000000 --- a/Library/Phalcon/Logger/Formatter/Firelogger.php +++ /dev/null @@ -1,378 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Logger\Formatter; - -use Phalcon\Logger\Formatter; -use Phalcon\Logger as Logger; -use Phalcon\Logger\FormatterInterface; - -/** - * Phalcon\Logger\Formatter\Firelogger - * Formats messages to be sent to Firelogger - * - * @link http://firelogger.binaryage.com/ - */ -class Firelogger extends Formatter implements FormatterInterface -{ - /** - * Holds name of this logger. - * - * @var string - */ - protected $name; - - /** - * Optional CSS snippet for logger icon in Firelogger console. - * - * @var string - */ - protected $style; - - /** - * encoding - * - * @var string - */ - protected $encoding = 'UTF-8'; - - /** - * Maximum recursion for pickle method - * - * @var integer - */ - protected $maxPickleDepth = 10; - - /** - * Class constructor. - * - * @param string $name - */ - public function __construct($name = 'logger') - { - $this->name = $name; - } - - /** - * Setter for _name - * - * @param string $name - * @return \Phalcon\Logger\Formatter\Firelogger - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Setter for style - * - * @param string $style - * @return \Phalcon\Logger\Formatter\Firelogger - */ - public function setStyle($style) - { - $this->style = $style; - - return $this; - } - - /** - * Translates Phalcon log types into Firelogger log level strings. - * - * @param integer $type - * @return string - */ - public function getTypeString($type) - { - switch ($type) { - case Logger::EMERGENCY: - case Logger::EMERGENCE: - case Logger::CRITICAL: - // emergence, critical - return 'critical'; - - case Logger::ALERT: - case Logger::ERROR: - // error, alert - return 'error'; - - case Logger::WARNING: - // warning - return 'warning'; - - case Logger::NOTICE: - case Logger::INFO: - // info, notice - return 'info'; - - case Logger::DEBUG: - case Logger::CUSTOM: - case Logger::SPECIAL: - default: - // debug, log, custom, special - return 'debug'; - } - } - - /** - * Applies a format to a message before sent it to the internal log - * - * @param string|integer|float|array|null|\Exception $message - * @param integer $type - * @param integer $timestamp - * @param array $context - * @param array $trace This is the output from debug_backtrace(). - * @param integer $order How many logs are stored in the stack already. - * @return mixed - */ - public function format($message, $type, $timestamp, $context = [], $trace = null, $order = 0) - { - $level = $this->getTypeString($type); - - if ($message instanceof \Exception) { - $exception = $message; - $message = ''; - } elseif (!is_string($message)) { - $richMessage = $message; - $message = ''; - } - - $item = [ - 'name' => $this->name, - 'args' => [], - 'level' => $level, - 'timestamp' => $timestamp, - 'order' => $order, // PHP is really fast, timestamp has insufficient resolution for log records ordering - 'time' => gmdate('H:i:s', (int) $timestamp) . '.000', - 'template' => $message, - 'message' => $message, - ]; - - if ($this->style) { - $item['style'] = $this->style; - } - - if (isset($exception)) { - // exception with backtrace - $traceInfo = $this->extractTrace( - $exception->getTrace() - ); - - $item['exc_info'] = [ - $exception->getMessage(), - $exception->getFile(), - $traceInfo[0] - ]; - - $item['exc_frames'] = $traceInfo[1]; - $item['exc_text'] = get_class($exception); - $item['template'] = $exception->getMessage(); - $item['code'] = $exception->getCode(); - $item['pathname'] = $exception->getFile(); - $item['lineno'] = $exception->getLine(); - } else { - // rich log record - $backtrace = debug_backtrace(); - list($file, $line) = $this->extractFileLine($backtrace); - - $item['pathname'] = $file; - $item['lineno'] = $line; - - if (isset($trace)) { - $traceInfo = $this->extractTrace($trace); - - $item['exc_info'] = [ - '', - '', - $traceInfo[0] - ]; - - $item['exc_frames'] = $traceInfo[1]; - } - - if (isset($richMessage)) { - $item['args'] = [$richMessage]; - } - } - - return $this->pickle($item); - } - - /** - * Reformats the passed log item. Recursive. - * - * @param mixed $var - * @param integer $level - * @return mixed - */ - protected function pickle($var, $level = 0) - { - if (is_bool($var) || is_null($var) || is_int($var) || is_float($var)) { - return $var; - } - - if (is_string($var)) { - // intentionally @ - return @iconv( - 'UTF-16', - 'UTF-8//IGNORE', - iconv($this->encoding, 'UTF-16//IGNORE', $var) - ); - } - - if (is_array($var)) { - static $marker; - if ($marker === null) { - $marker = uniqid("\x00", true); - } // detects recursions - - if (isset($var[$marker])) { - return '*RECURSION*'; - } - - if ($this->maxPickleDepth && $level >= $this->maxPickleDepth) { - return '...'; - } - - $var[$marker] = true; - $res = []; - - foreach ($var as $k => &$v) { - if ($k !== $marker) { - $res[$this->pickle($k)] = $this->pickle($v, $level + 1); - } - } - - unset($var[$marker]); - - return $res; - } - - if (is_object($var)) { - $arr = (array) $var; - $arr['__class##'] = get_class($var); - - static $list = []; // detects recursions - if (in_array($var, $list, true)) { - return '*RECURSION*'; - } - - if ($level < $this->maxPickleDepth || !$this->maxPickleDepth) { - $list[] = $var; - $res = []; - - foreach ($arr as $k => &$v) { - if ($k[0] === "\x00") { - $k = substr( - $k, - strrpos($k, "\x00") + 1 - ); - } - - $res[$this->pickle($k)] = $this->pickle($v, $level + 1); - } - - array_pop($list); - - return $res; - } - - return '...'; - } - - if (is_resource($var)) { - return '*' . get_resource_type($var) . ' resource*'; - } - - return '*unknown type*'; - } - - /** - * Extract useful information from exception traces. - * - * @param array $trace - * @return array - */ - protected function extractTrace($trace) - { - $t = []; - $f = []; - - foreach ($trace as $frame) { - // prevent notices about invalid indices, wasn't able to google smart solution, PHP is dumb ass - $frame += [ - 'file' => null, - 'line' => null, - 'class' => null, - 'type' => null, - 'function' => null, - 'object' => null, - 'args' => null, - ]; - - $t[] = [ - $frame['file'], - $frame['line'], - $frame['class'] . $frame['type'] . $frame['function'], - $frame['object'], - ]; - - $f[] = $frame['args']; - }; - - return [$t, $f]; - } - - /** - * Extracts useful information from debug_backtrace() - * - * @param array $trace Array returned by debug_backtrace() - * @return array - */ - protected function extractFileLine($trace) - { - while (count($trace) && !array_key_exists('file', $trace[0])) { - array_shift($trace); - } - - $thisFile = $trace[0]['file']; - while (count($trace) && (array_key_exists('file', $trace[0]) && $trace[0]['file'] == $thisFile)) { - array_shift($trace); - } - - while (count($trace) && !array_key_exists('file', $trace[0])) { - array_shift($trace); - } - - if (count($trace) == 0) { - return ["?", "0"]; - } - - $file = $trace[0]['file']; - $line = $trace[0]['line']; - - return [ - $file, - $line, - ]; - } -} diff --git a/Library/Phalcon/Logger/README.md b/Library/Phalcon/Logger/README.md deleted file mode 100644 index de2a0c0c3..000000000 --- a/Library/Phalcon/Logger/README.md +++ /dev/null @@ -1,166 +0,0 @@ -# Phalcon\Logger\Adapter - -Usage examples of the adapters available here: - -## Database - -Adapter to store logs in a database table: - -```php -use Phalcon\Db\Adapter\Pdo\Mysql; -use Phalcon\Logger\Adapter\Database as DbLogger; - -$di->set( - 'logger', - function () { - $connection = new Mysql( - [ - 'host' => 'localhost', - 'username' => 'root', - 'password' => 'secret', - 'dbname' => 'audit', - ] - ); - - $logger = new DbLogger( - 'errors', - [ - 'db' => $connection, - 'table' => 'logs', - ] - ); - - return $logger; - } -); -``` - -The following table is used to store the logs: - -```sql -CREATE TABLE `logs` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(32) DEFAULT NULL, - `type` int(3) NOT NULL, - `content` text, - `created_at` int(18) unsigned NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 -``` - -## Firelogger - -Adapter to send messages to the [Firelogger][1] console inside the [Firebug][2] in your browser. - -```php -use Phalcon\Logger\Adapter\Firelogger; - -$logger = new Firelogger('debug'); - -$logger->log('Plain Message'); -$logger->info('Info Message'); -// etc -``` - -## UDP logger - -Adapter to send messages by UDP protocol to external server - -```php -use Phalcon\Logger\Adapter\Udplogger as UdpLogger; - -$di->set( - 'logger', - function () { - $logger = new UdpLogger( - 'errors', - [ - 'url' => $url, - 'port' => $port, - ] - ); - - return $logger; - } -); -``` - -## Multiple file logger - -Adapter `Phalcon\Logger\Adapter\File\Multiple` can be used to log messages to multiple files. This is similar to the core -`Phalcon\Logger\Adapter\File` adapter with two important distinctions: -* messages are logged into separate files by their log levels -* prefix for log files can be specified, thus allowing us to have separate log files for individual applications in a multi-app project - -```php -use Phalcon\Logger\Adapter\File\Multiple as MultipleLogger; -use Phalcon\Logger; - -$logger = new MultipleLogger(__DIR__ . '/../logs'); - -$logger->debug('Hello world'); // this is logged into debug.log -$logger->info('Hello world'); // this is logged into info.log -$logger->warning('Hello world'); // this is logged into warning.log -$logger->error('Hello world'); // this is logged into error.log -$logger->log('Hello world', Logger::CRITICAL); // this is logged into critical.log - -``` - -### Message grouping by their level - -Note that similar-level logs are logged into the same file. -The log level groups are defined within the `getTypeString()` method. You may overload this method to fit your needs: - -```php -private function getTypeString($type) -{ - switch ($type) { - case Logger::EMERGENCY: - case Logger::EMERGENCE: - case Logger::CRITICAL: - // emergence, critical - return 'critical'; - case Logger::ALERT: - case Logger::ERROR: - // error, alert - return 'error'; - case Logger::WARNING: - // warning - return 'warning'; - case Logger::NOTICE: - case Logger::INFO: - // info, notice - return 'info'; - case Logger::DEBUG: - case Logger::CUSTOM: - case Logger::SPECIAL: - default: - // debug, log, custom, special - return 'debug'; - } -} -``` - -Thus, by default both errors and alerts are logged into error.log, and both emergence and critical messages are logged into critical.log, etc. - -### Configuration options - -Optionally, you may pass configuration options to the logger constructor: - -```php -use Phalcon\Logger\Adapter\File\Multiple as MultipleLogger; - -$logger = new MultipleLogger( - __DIR__ . '/../logs', - [ - // filename prefix to all logs generated by this logger. Defaults to "" - 'prefix' => 'myapp-', - // filename extension to all logs generated by this logger. Defaults to "log" - 'extension' => 'txt', - ] -); -``` - - -[1]: http://firelogger.binaryage.com/ -[2]: https://getfirebug.com/ diff --git a/composer.json b/composer.json index b7bbb4404..1ed7d4d2b 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,9 @@ "php": ">=7.2", "ext-phalcon": "^4.0", "phalcon/incubator-acl": "^1.0.0-alpha.1", - "phalcon/incubator-session": "^1.0.0", - "phalcon/incubator-test": "^1.0.0-alpha.1" + "phalcon/incubator-session": "^1.0", + "phalcon/incubator-test": "^1.0.0-alpha.1", + "phalcon/incubator-logger": "^1.0" }, "require-dev": { "phpdocumentor/reflection-docblock": "2.0.4", @@ -65,5 +66,7 @@ "files": [ "tests/_support/functions.php" ] - } + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/composer.lock b/composer.lock index 925418e64..45c2e6a96 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "423a0902d0f7c2d95ca902c32f598a01", + "content-hash": "e4c6647fa72e1ba200fedff45d7bfdca", "packages": [ { "name": "behat/gherkin", @@ -822,6 +822,84 @@ ], "time": "2020-04-13T22:00:37+00:00" }, + { + "name": "phalcon/incubator-logger", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/phalcon/incubator-logger.git", + "reference": "4e105994b32e290a7474a8c3c8078c932b4c7891" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phalcon/incubator-logger/zipball/4e105994b32e290a7474a8c3c8078c932b4c7891", + "reference": "4e105994b32e290a7474a8c3c8078c932b4c7891", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-phalcon": "^4.0", + "php": ">=7.2" + }, + "require-dev": { + "aws/aws-sdk-php": "^3.145", + "codeception/codeception": "^4.1", + "codeception/module-asserts": "^1.0.0", + "codeception/module-db": "^1.0", + "phalcon/ide-stubs": "^4.0", + "phpstan/phpstan": "^0.12.18", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^3.6" + }, + "suggest": { + "aws/aws-sdk-php": "Needed to run in CloudWatch Logger Adapter", + "ext-sockets": "Needed to run in Udp Logger Adapter" + }, + "type": "library", + "autoload": { + "psr-4": { + "Phalcon\\Incubator\\Logger\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Phalcon Team", + "email": "team@phalcon.io", + "homepage": "https://phalcon.io/en/team" + }, + { + "name": "Contributors", + "homepage": "https://github.com/phalcon/incubator-logger/graphs/contributors" + } + ], + "description": "Phalcon Incubator Logger Adapters and Formatters", + "homepage": "https://phalcon.io", + "keywords": [ + "aws", + "framework", + "incubator", + "log formatter", + "logger", + "monolog", + "phalcon", + "psr-3" + ], + "funding": [ + { + "url": "https://github.com/phalcon", + "type": "github" + }, + { + "url": "https://opencollective.com/phalcon", + "type": "open_collective" + } + ], + "time": "2020-07-29T20:10:36+00:00" + }, { "name": "phalcon/incubator-session", "version": "v1.0.0", @@ -3957,12 +4035,9 @@ } ], "aliases": [], - "minimum-stability": "stable", - "stability-flags": { - "phalcon/incubator-acl": 15, - "phalcon/incubator-test": 15 - }, - "prefer-stable": false, + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, "prefer-lowest": false, "platform": { "php": ">=7.2", diff --git a/tests/unit/Legacy/CryptTest.php b/tests/unit/Legacy/CryptTest.php deleted file mode 100644 index f27e6148a..000000000 --- a/tests/unit/Legacy/CryptTest.php +++ /dev/null @@ -1,179 +0,0 @@ - - * @package Phalcon\Test\Legacy - * @group crypt - * - * The contents of this file are subject to the New BSD License that is - * bundled with this package in the file docs/LICENSE.txt - * - * If you did not receive a copy of the license and are unable to obtain it - * through the world-wide-web, please send an email to license@phalconphp.com - * so that we can send you a copy immediately. - */ -class CryptTest extends Test -{ - use Specify; - - public function _before() - { - parent::_before(); - - if (!extension_loaded('mcrypt')) { - $this->markTestSkipped('Warning: mcrypt extension is not loaded'); - } - } - - - /** - * Tests the Crypt constants - * - * @author Serghei Iakovlev - * @since 2015-12-20 - */ - public function testCryptConstants() - { - $this->specify( - "Crypt constants are not correct", - function ($const, $expected) { - expect($const)->equals($expected); - }, - [ - 'examples' => [ - [Crypt::PADDING_DEFAULT, 0], - [Crypt::PADDING_ANSI_X_923, 1], - [Crypt::PADDING_PKCS7, 2], - [Crypt::PADDING_ISO_10126, 3], - [Crypt::PADDING_ISO_IEC_7816_4, 4], - [Crypt::PADDING_ZERO, 5], - [Crypt::PADDING_SPACE, 6], - ], - ] - ); - } - - /** - * Tests the encryption - * - * @author Nikolaos Dimopoulos - * @since 2014-10-17 - */ - public function testCryptEncryption() - { - $this->specify( - "encryption does not return correct results", - function ($key, $test) { - $modes = [ - MCRYPT_MODE_ECB, - MCRYPT_MODE_CBC, - MCRYPT_MODE_CFB, - MCRYPT_MODE_OFB, - MCRYPT_MODE_NOFB, - ]; - - $crypt = new Crypt(); - - foreach ($modes as $mode) { - $crypt->setMode($mode); - $crypt->setKey(substr($key, 0, 16)); - - $encryption = $crypt->encrypt($test); - expect(rtrim($crypt->decrypt($encryption), "\0"))->equals($test); - - $encryption = $crypt->encrypt($test, substr($key, 0, 16)); - expect(rtrim($crypt->decrypt($encryption, substr($key, 0, 16)), "\0"))->equals($test); - } - }, - [ - 'examples' => [ - [md5(uniqid()), str_repeat('x', mt_rand(1, 255))], - [time().time(), str_shuffle(join('', range('a', 'z')))], - ['le$ki12432543543543543', null], - ], - ] - ); - } - - /** - * Tests the padding - * - * @author Nikolaos Dimopoulos - * @since 2014-10-17 - */ - public function testCryptPadding() - { - $this->specify( - "padding not return correct results", - function () { - $texts = ['']; - $key = '0123456789ABCDEF0123456789ABCDEF'; - $modes = [MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB]; - $pads = [ - Crypt::PADDING_ANSI_X_923, - Crypt::PADDING_PKCS7, - ]; - - for ($i = 1; $i < 128; ++$i) { - $texts[] = str_repeat('A', $i); - } - - $crypt = new Crypt(); - - $crypt->setCipher(MCRYPT_RIJNDAEL_256) - ->setKey(substr($key, 0, 16)); - - foreach ($pads as $padding) { - $crypt->setPadding($padding); - - foreach ($modes as $mode) { - $crypt->setMode($mode); - - foreach ($texts as $text) { - $encrypted = $crypt->encrypt($text); - expect($crypt->decrypt($encrypted))->equals($text); - } - } - } - } - ); - } - - /** - * Tests the encryption base 64 - * - * @author Nikolaos Dimopoulos - * @since 2014-10-17 - */ - public function testCryptEncryptBase64() - { - $this->specify( - "encryption base 64does not return correct results", - function () { - $crypt = new Crypt(); - - $crypt->setPadding(Crypt::PADDING_ANSI_X_923); - - $key = substr('phalcon notice 13123123', 0, 16); - $expected = 'https://github.com/phalcon/cphalcon/issues?state=open'; - - $encrypted = $crypt->encryptBase64($expected, substr($key, 0, 16)); - expect($crypt->decryptBase64($encrypted, $key))->equals($expected); - - $encrypted = $crypt->encryptBase64($expected, $key, true); - expect($crypt->decryptBase64($encrypted, $key, true))->equals($expected); - } - ); - } -}