[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Filter / Encrypt.php
blob515738e93504ab2b34751fc61970206d41d8f5aa
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_Filter
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id$
22 /**
23 * @see Zend_Filter_Interface
25 require_once 'Zend/Filter/Interface.php';
27 /**
28 * @see Zend_Loader
30 require_once 'Zend/Loader.php';
32 /**
33 * Encrypts a given string
35 * @category Zend
36 * @package Zend_Filter
37 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
38 * @license http://framework.zend.com/license/new-bsd New BSD License
40 class Zend_Filter_Encrypt implements Zend_Filter_Interface
42 /**
43 * Encryption adapter
45 protected $_adapter;
47 /**
48 * Class constructor
50 * @param string|array $options (Optional) Options to set, if null mcrypt is used
52 public function __construct($options = null)
54 if ($options instanceof Zend_Config) {
55 $options = $options->toArray();
58 $this->setAdapter($options);
61 /**
62 * Returns the name of the set adapter
64 * @return string
66 public function getAdapter()
68 return $this->_adapter->toString();
71 /**
72 * Sets new encryption options
74 * @param string|array $options (Optional) Encryption options
75 * @return Zend_Filter_Encrypt
77 public function setAdapter($options = null)
79 if (is_string($options)) {
80 $adapter = $options;
81 } else if (isset($options['adapter'])) {
82 $adapter = $options['adapter'];
83 unset($options['adapter']);
84 } else {
85 $adapter = 'Mcrypt';
88 if (!is_array($options)) {
89 $options = array();
92 if (Zend_Loader::isReadable('Zend/Filter/Encrypt/' . ucfirst($adapter). '.php')) {
93 $adapter = 'Zend_Filter_Encrypt_' . ucfirst($adapter);
96 if (!class_exists($adapter)) {
97 Zend_Loader::loadClass($adapter);
100 $this->_adapter = new $adapter($options);
101 if (!$this->_adapter instanceof Zend_Filter_Encrypt_Interface) {
102 require_once 'Zend/Filter/Exception.php';
103 throw new Zend_Filter_Exception("Encoding adapter '" . $adapter . "' does not implement Zend_Filter_Encrypt_Interface");
106 return $this;
110 * Calls adapter methods
112 * @param string $method Method to call
113 * @param string|array $options Options for this method
115 public function __call($method, $options)
117 $part = substr($method, 0, 3);
118 if ((($part != 'get') and ($part != 'set')) or !method_exists($this->_adapter, $method)) {
119 require_once 'Zend/Filter/Exception.php';
120 throw new Zend_Filter_Exception("Unknown method '{$method}'");
123 return call_user_func_array(array($this->_adapter, $method), $options);
127 * Defined by Zend_Filter_Interface
129 * Encrypts the content $value with the defined settings
131 * @param string $value Content to encrypt
132 * @return string The encrypted content
134 public function filter($value)
136 return $this->_adapter->encrypt($value);