3 * The core Encryption Factory
7 * @category PHPCryptLib
9 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
10 * @copyright 2011 The Authors
11 * @license http://www.opensource.org/licenses/mit-license.html MIT License
12 * @version Build @@version@@
15 namespace CryptLib\Encryption
;
17 use CryptLib\Cipher\Factory
as CipherFactory
;
20 * The core Encryption Factory
24 * @category PHPCryptLib
26 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
28 class Factory
extends \CryptLib\Core\AbstractFactory
{
31 * @var Factory The Cipher Factory to use for this instance
33 protected $cipherFactory = null;
36 * @var array An array of PackingModes available for use
38 protected $packingModes = array();
43 * @param Factory $factory The Cipher Factory to use for this instance
47 public function __construct(CryptoLib\Cipher\Factory
$factory = null) {
48 if (is_null($factory)) {
49 $factory = new CipherFactory();
51 $this->cipherFactory
= $factory;
52 $this->loadPackingModes();
56 * Get a packing mode by name
58 * @param string|PackingMode $name The name of the packing mode or instance
60 * @return PackingMode The instantiated PackingMode class
61 * @throws RuntimeException If the mode does not exist
63 public function getPackingMode($name) {
64 if (is_object($name) && $name instanceof PackingMode
) {
67 $name = strtolower($name);
68 if (isset($this->packingModes
[$name])) {
69 $class = $this->packingModes
[$name];
72 $message = sprintf('Invalid Mode Supplied: %s', $name);
73 throw new \
RuntimeException($message);
77 * Register a new packing mode by name
79 * @param string $name The name of the packing mode
80 * @param string $class The class to instantiate for the mode
82 * @return Factory $this The current factory instance
84 public function registerPackingMode($name, $class) {
87 __NAMESPACE__
. '\\PackingMode',
95 * Load the core packing modes for this instance
99 protected function loadPackingModes() {
101 __DIR__
. '/PackingMode',
102 __NAMESPACE__
. '\\PackingMode\\',
103 array($this, 'registerPackingMode')