public function setUp() { if (!class_exists('Archive_Tar')) { try { \Zend\Loader::loadClass('Archive_Tar'); } catch (\Zend\Loader\Exception $e) { $this->markTestSkipped('This filter needs PEARs Archive_Tar'); } } $files = array(dirname(__DIR__) . '/_files/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First/Second/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First/Second', dirname(__DIR__) . '/_files/_compress/Compress/First/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress/First', dirname(__DIR__) . '/_files/_compress/Compress/zipextracted.txt', dirname(__DIR__) . '/_files/_compress/Compress', dirname(__DIR__) . '/_files/_compress/zipextracted.txt', dirname(__DIR__) . '/_files/_compress', dirname(__DIR__) . '/_files/compressed.tar'); foreach ($files as $file) { if (file_exists($file)) { if (is_dir($file)) { rmdir($file); } else { unlink($file); } } } if (!file_exists(dirname(__DIR__) . '/_files/Compress/First/Second')) { mkdir(dirname(__DIR__) . '/_files/Compress/First/Second', 0777, true); file_put_contents(dirname(__DIR__) . '/_files/Compress/First/Second/zipextracted.txt', 'compress me'); file_put_contents(dirname(__DIR__) . '/_files/Compress/First/zipextracted.txt', 'compress me'); file_put_contents(dirname(__DIR__) . '/_files/Compress/zipextracted.txt', 'compress me'); } }
/** * ZF-2017: Test bind use of the Zend_Db_Select class. */ public function testSelectQueryWithBinds() { $select = $this->_select()->where('product_id = :product_id')->bind(array(':product_id' => 1)); $sql = preg_replace('/\\s+/', ' ', $select->__toString()); $this->assertEquals('SELECT "zfproducts".* FROM "zfproducts" WHERE (product_id = :product_id)', $sql); $stmt = $select->query(); \Zend\Loader::loadClass('Zend_Db_Statement_Static'); $this->assertInstanceOf('Zend_Db_Statement_Static', $stmt); }
public function setAdapter($adapter) { if (is_string($adapter)) { $storageAdapterClass = 'Zend\\Tool\\Framework\\Client\\Storage\\' . ucfirst($adapter); \Zend\Loader::loadClass($storageAdapterClass); $adapter = new $storageAdapterClass(); } $this->_adapter = $adapter; }
/** * Class constructor * * @param array $options (Optional) Options to set */ public function __construct($options = null) { if (!class_exists('Archive_Tar')) { try { \Zend\Loader::loadClass('Archive_Tar'); } catch (\Exception $e) { throw new Exception\ExtensionNotLoadedException('This filter needs PEARs Archive_Tar', 0, $e); } } parent::__construct($options); }
public function addContextClass($contextClass) { if (!class_exists($contextClass)) { \Zend\Loader::loadClass($contextClass); } $reflectionContextClass = new \ReflectionClass($contextClass); if ($reflectionContextClass->isInstantiable()) { $context = new $contextClass(); return $this->addContext($context); } return $this; }
protected function _getTable($tableClass, $options = array()) { if (is_array($options) && !isset($options['db'])) { $options['db'] = $this->_db; } if (!class_exists($tableClass)) { $this->_useMyIncludePath(); \Zend\Loader::loadClass($tableClass); $this->_restoreIncludePath(); } $table = new $tableClass($options); return $table; }
/** * Sets a new adapter * * @param string $adapter Adapter to use * @param boolean $direction OPTIONAL False means Download, true means upload * @param array $options OPTIONAL Options to set for this adapter * @throws \Zend\File\Transfer\Exception */ public function setAdapter($adapter, $direction = false, $options = array()) { if (\Zend\Loader::isReadable('Zend/File/Transfer/Adapter/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend\\File\\Transfer\\Adapter\\' . ucfirst($adapter); } if (!class_exists($adapter)) { \Zend\Loader::loadClass($adapter); } $direction = (int) $direction; $this->_adapter[$direction] = new $adapter($options); if (!$this->_adapter[$direction] instanceof Adapter\AbstractAdapter) { throw new Transfer\Exception("Adapter " . $adapter . " does not extend Zend_File_Transfer_Adapter_Abstract"); } return $this; }
/** * Converts a DOMElement object into the specific class * * @throws \Zend\InfoCard\XML\Exception * @param DOMElement $e The DOMElement object to convert * @param string $classname The name of the class to convert it to (must inhert from \Zend\InfoCard\XML\Element) * @return \Zend\InfoCard\XML\Element a Xml Element object from the DOM element */ public static function convertToObject(\DOMElement $e, $classname) { if (!class_exists($classname)) { \Zend\Loader::loadClass($classname); } if (!is_subclass_of($classname, 'Zend\\InfoCard\\XML\\Element')) { throw new Exception\InvalidArgumentException("DOM element must be converted to an instance of Zend_InfoCard_Xml_Element"); } $sxe = simplexml_import_dom($e, $classname); if (!$sxe instanceof Element) { // Since we just checked to see if this was a subclass of Zend_infoCard_Xml_Element this shoudl never fail // @codeCoverageIgnoreStart throw new Exception\RuntimeException("Failed to convert between DOM and SimpleXML"); // @codeCoverageIgnoreEnd } return $sxe; }
/** * Create XML definition on an AMF service class * * @param string $serviceClass Service class name * @param array $options invocation options * @return string XML with service class introspection */ public function introspect($serviceClass, $options = array()) { $this->_options = $options; if (strpbrk($serviceClass, '\\/<>')) { return $this->_returnError('Invalid service name'); } // Transform com.foo.Bar into com\foo\Bar $serviceClass = str_replace('.', '\\', $serviceClass); // Introspect! if (!class_exists($serviceClass)) { \Zend\Loader::loadClass($serviceClass, $this->_getServicePath()); } $serv = $this->_xml->createElement('service-description'); $serv->setAttribute('xmlns', 'http://ns.adobe.com/flex/service-description/2008'); $this->_types = $this->_xml->createElement('types'); $this->_ops = $this->_xml->createElement('operations'); $r = \Zend\Server\Reflection::reflectClass($serviceClass); $this->_addService($r, $this->_ops); $serv->appendChild($this->_types); $serv->appendChild($this->_ops); $this->_xml->appendChild($serv); return $this->_xml->saveXML(); }
/** * Set the container class to use * * @param string $name * @return \Zend\View\Helper\Placeholder\Registry\Registry */ public function setContainerClass($name) { if (!class_exists($name)) { \Zend\Loader::loadClass($name); } //$reflection = new \ReflectionClass($name); //if (!$reflection->isSubclassOf(new \ReflectionClass('Zend\View\Helper\Placeholder\Container\AbstractContainer'))) { if (!in_array('Zend\\View\\Helper\\Placeholder\\Container\\AbstractContainer', class_parents($name))) { $e = new Exception('Invalid Container class specified'); //$e->setView($this->view); throw $e; } $this->_containerClass = $name; return $this; }
/** * Construct a filter or writer from config * * @param string $type 'writer' of 'filter' * @param mixed $config Config or Array * @param string $namespace * @throws Exception\InvalidArgumentException * @return object */ protected function _constructFromConfig($type, $config, $namespace) { if ($config instanceof Config) { $config = $config->toArray(); } if (!is_array($config) || empty($config)) { throw new Exception\InvalidArgumentException('Configuration must be an array or instance of Zend\\Config\\Config'); } $params = isset($config[$type . 'Params']) ? $config[$type . 'Params'] : array(); $className = $this->getClassName($config, $type, $namespace); if (!class_exists($className)) { \Zend\Loader::loadClass($className); } $reflection = new ReflectionClass($className); if (!$reflection->implementsInterface('Zend\\Log\\Factory')) { throw new Exception\InvalidArgumentException($className . ' does not implement Zend\\Log\\Factory and can not be constructed from config.'); } return $className::factory($params); }
/** * Initialize front controller plugin * * @return void */ protected function _initPlugin() { $pluginClass = $this->getPluginClass(); $front = Controller\Front::getInstance(); if (!$front->hasPlugin($pluginClass)) { if (!class_exists($pluginClass)) { \Zend\Loader::loadClass($pluginClass); } $front->registerPlugin(new $pluginClass($this), 99); } }
/** * Provides a magic factory method to instantiate new objects with * shorter syntax than would otherwise be required by the Zend Framework * naming conventions. For more information, see Zend_Gdata_App::__call(). * * This overrides the default behavior of __call() so that query classes * do not need to have their domain manually set when created with * a magic factory method. * * @see Zend_Gdata_App::__call() * @param string $method The method name being called * @param array $args The arguments passed to the call * @throws \Zend\GData\App\Exception */ public function __call($method, $args) { if (preg_match('/^new(\\w+Query)/', $method, $matches)) { $class = $matches[1]; $foundClassName = null; foreach ($this->_registeredPackages as $name) { try { // Autoloading disabled on next line for compatibility // with magic factories. See ZF-6660. if (!class_exists($name . '\\' . $class, false)) { @\Zend\Loader::loadClass($name . '\\' . $class); } $foundClassName = $name . '\\' . $class; break; } catch (\Zend\Exception $e) { // package wasn't here- continue searching } } if ($foundClassName != null) { $reflectionObj = new \ReflectionClass($foundClassName); // Prepend the domain to the query $args = array_merge(array($this->getDomain()), $args); return $reflectionObj->newInstanceArgs($args); } else { throw new App\Exception("Unable to find '{$class}' in registered packages"); } } else { return parent::__call($method, $args); } }
/** * Prepare a statement and return a PdoStatement-like object. * * @param string $sql SQL query * @return \Zend\Db\Statement\Mysqli */ public function prepare($sql) { $this->_connect(); if ($this->_stmt) { $this->_stmt->close(); } $stmtClass = $this->_defaultStmtClass; if (!class_exists($stmtClass)) { \Zend\Loader::loadClass($stmtClass); } $stmt = new $stmtClass($this, $sql); if ($stmt === \false) { return false; } $stmt->setFetchMode($this->_fetchMode); $this->_stmt = $stmt; return $stmt; }
/** * Constructor. * * @param array $config */ public function __construct(array $config) { if (isset($config['table'])) { $this->_table = $config['table']; $this->_tableClass = get_class($this->_table); } if (isset($config['rowClass'])) { $this->_rowClass = $config['rowClass']; } if (!class_exists($this->_rowClass)) { \Zend\Loader::loadClass($this->_rowClass); } if (isset($config['data'])) { $this->_data = $config['data']; } if (isset($config['readOnly'])) { $this->_readOnly = $config['readOnly']; } if (isset($config['stored'])) { $this->_stored = $config['stored']; } // set the count of rows $this->_count = count($this->_data); $this->init(); }
public function testTableMetadataCacheException() { \Zend\Loader::loadClass('\\ZendTest\\Db\\Table\\TestAsset\\TableBugs'); /** * options array points 'metadataCache' to integer scalar */ try { $table = new \ZendTest\Db\Table\TestAsset\TableBugs(array('metadataCache' => 327)); $this->fail('Expected to catch Zend_Db_Table_Exception'); } catch (\Zend\Exception $e) { $this->assertType('Zend\\Db\\Table\\Exception', $e, 'Expecting object of type Zend_Db_Table_Exception, got ' . get_class($e)); $this->assertEquals("Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored", $e->getMessage()); } /** * options array points 'metadataCache' to Registry key containing integer scalar */ \Zend\Registry::set('registered_metadata_cache', 327); try { $table = new \ZendTest\Db\Table\TestAsset\TableBugs(array('metadataCache' => 'registered_metadata_cache')); $this->fail('Expected to catch Zend_Db_Table_Exception'); } catch (\Zend\Exception $e) { $this->assertType('Zend\\Db\\Table\\Exception', $e, 'Expecting object of type Zend_Db_Table_Exception, got ' . get_class($e)); $this->assertEquals("Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored", $e->getMessage()); } }
/** * Set response class/object * * Set the response object. The response is a container for action * responses and headers. Usage is optional. * * If a class name is provided, instantiates a response object. * * @param string|\Zend\Controller\Response\AbstractResponse $response * @throws \Zend\Controller\Exception if invalid response class * @return \Zend\Controller\Front */ public function setResponse($response) { if (is_string($response)) { if (!class_exists($response)) { \Zend\Loader::loadClass($response); } $response = new $response(); } if (!$response instanceof Response\AbstractResponse) { throw new Exception('Invalid response class'); } $this->_response = $response; return $this; }
/** * Returns an SQL statement for preparation. * * @param string $sql The SQL statement with placeholders. * @return \Zend\DB\Statement\Oracle\Oracle */ public function prepare($sql) { $this->_connect(); $stmtClass = $this->_defaultStmtClass; if (!class_exists($stmtClass)) { \Zend\Loader::loadClass($stmtClass); } $stmt = new $stmtClass($this, $sql); if ($stmt instanceof DB\Statement\Oracle\Oracle) { $stmt->setLobAsString($this->getLobAsString()); } $stmt->setFetchMode($this->_fetchMode); return $stmt; }
/** * Renderer Constructor * * @param mixed $renderer String name of renderer class, or \Zend\Config\Config object. * @param mixed $rendererConfig OPTIONAL; an array or \Zend\Config\Config object with renderer parameters. * @return \Zend\Barcode\Renderer\RendererInterface */ public static function makeRenderer($renderer = 'image', $rendererConfig = array()) { if ($renderer instanceof Renderer\RendererInterface) { return $renderer; } /* * Convert \Zend\Config\Config argument to plain string * barcode name and separate config object. */ if ($renderer instanceof Config\Config) { if (isset($renderer->rendererParams)) { $rendererConfig = $renderer->rendererParams->toArray(); } if (isset($renderer->renderer)) { $renderer = (string) $renderer->renderer; } } if ($rendererConfig instanceof Config\Config) { $rendererConfig = $rendererConfig->toArray(); } /* * Verify that barcode parameters are in an array. */ if (!is_array($rendererConfig)) { $e = new Exception('Barcode parameters must be in an array or a \\Zend\\Config\\Config object'); $e->setIsRenderable(false); throw $e; } /* * Verify that an barcode name has been specified. */ if (!is_string($renderer) || empty($renderer)) { $e = new Exception('Renderer name must be specified in a string'); $e->setIsRenderable(false); throw $e; } /* * Form full barcode class name */ $rendererNamespace = '\\Zend\\Barcode\\Renderer'; if (isset($rendererConfig['rendererNamespace'])) { $rendererNamespace = $rendererConfig['rendererNamespace']; } /** @todo Check if it's correct to drop case transformation */ $rendererName = $rendererNamespace . '\\' . ucfirst($renderer); /* * Load the renderer class. * Important! This throws an exception if the specified class cannot be loaded. */ if (!class_exists($rendererName, false)) { Loader::loadClass($rendererName); } /* * Create an instance of the barcode class. * Pass the config to the barcode class constructor. */ $rdrAdapter = new $rendererName($rendererConfig); /* * Verify that the object created is a descendent of the abstract barcode type. */ if (!$rdrAdapter instanceof Renderer\RendererInterface) { $e = new Exception("Renderer class '{$rendererName}' does not implements \\Zend\\Barcode\\Renderer\\RendererInterface"); $e->setIsRenderable(false); throw $e; } return $rdrAdapter; }
/** * Adds a timeserver object to the timeserver list * * @param string|array $target - Single timeserver, or an array of timeservers. * @param string $alias - An alias for this timeserver */ protected function _addServer($target, $alias) { if ($pos = strpos($target, '://')) { $protocol = substr($target, 0, $pos); $address = substr($target, $pos + 3); } else { $address = $target; $protocol = self::DEFAULT_PROTOCOL; } if ($pos = strrpos($address, ':')) { $posbr = strpos($address, ']'); if ($posbr and $pos > $posbr) { $port = substr($address, $pos + 1); $address = substr($address, 0, $pos); } else { if (!$posbr and $pos) { $port = substr($address, $pos + 1); $address = substr($address, 0, $pos); } else { $port = null; } } } else { $port = null; } $protocol = ucfirst(strtolower($protocol)); if (!in_array($protocol, $this->_allowedSchemes)) { throw new Exception("'{$protocol}' is not a supported protocol"); } $className = 'Zend\\TimeSync\\' . $protocol; if (!class_exists($className)) { \Zend\Loader::loadClass($className); } $timeServerObj = new $className($address, $port); $this->_timeservers[$alias] = $timeServerObj; }
/** * Get a route frm a config instance * * @param \Zend\Config\Config $info * @return Zend_Controller_Router_Route_Interface */ protected function _getRouteFromConfig(\Zend\Config\Config $info) { $class = isset($info->type) ? $info->type : 'Zend_Controller_Router_Route'; if (!class_exists($class)) { \Zend\Loader::loadClass($class); } $route = call_user_func(array($class, 'getInstance'), $info); if (isset($info->abstract) && $info->abstract && method_exists($route, 'isAbstract')) { $route->isAbstract(true); } return $route; }
/** * Sets a new barcode adapter * * @param string|\Zend\Validator\Barcode\Barcode $adapter Barcode adapter to use * @param array $options Options for this adapter * @return void * @throws \Zend\Validator\Exception */ public function setAdapter($adapter, $options = null) { $adapter = ucfirst(strtolower($adapter)); // if (\Zend\Loader::isReadable('Zend/Validate/Barcode/' . $adapter. '.php')) { $adapter = '\\Zend\\Validator\\Barcode\\' . $adapter; // } // // if (!class_exists($adapter)) { \Zend\Loader::loadClass($adapter); // } $this->_adapter = new $adapter($options); if (!$this->_adapter instanceof AdapterInterface) { throw new Validator\Exception("Adapter " . $adapter . " does not implement Zend\\Validate\\Barcode\\AdapterInterface"); } return $this; }
/** * Apply the transforms in the transform list to the input XML document * * @param string $strXmlDocument The input XML * @return string The XML after the transformations have been applied */ public function applyTransforms($strXmlDocument) { foreach($this->_transformList as $transform) { if (!class_exists($transform['class'])) { \Zend\Loader::loadClass($transform['class']); } $transformer = new $transform['class']; // We can't really test this check because it would require logic changes in the component itself // @codeCoverageIgnoreStart if(!($transformer instanceof Transform)) { throw new Security\Exception\RuntimeExcpetion("Transforms must implement the Transform Interface"); } // @codeCoverageIgnoreEnd $strXmlDocument = $transformer->transform($strXmlDocument); } return $strXmlDocument; }
/** * Initialize action helper * * @return void */ protected function _initHelper() { $helperClass = $this->getHelperClass(); if (!HelperBroker\HelperBroker::hasHelper('layout')) { if (!class_exists($helperClass)) { \Zend\Loader::loadClass($helperClass); } HelperBroker\HelperBroker::getStack()->offsetSet(-90, new $helperClass($this)); } }
/** * Add a display group * * Groups named elements for display purposes. * * If a referenced element does not yet exist in the form, it is omitted. * * @param array $elements * @param string $name * @param array|\Zend\Config\Config $options * @return \Zend\Form\Form * @throws \Zend\Form\Exception\InvalidArgumentException if no valid elements provided */ public function addDisplayGroup(array $elements, $name, $options = null) { $group = array(); foreach ($elements as $element) { if (isset($this->_elements[$element])) { $add = $this->getElement($element); if (null !== $add) { unset($this->_order[$element]); $group[] = $add; } } } if (empty($group)) { throw new Exception\InvalidArgumentException('No valid elements specified for display group'); } $name = (string) $name; if (is_array($options)) { $options['elements'] = $group; } elseif ($options instanceof Config) { $options = $options->toArray(); $options['elements'] = $group; } else { $options = array('elements' => $group); } if (isset($options['displayGroupClass'])) { $class = $options['displayGroupClass']; unset($options['displayGroupClass']); } else { $class = $this->getDefaultDisplayGroupClass(); } if (!class_exists($class)) { Loader::loadClass($class); } $this->_displayGroups[$name] = new $class($name, $this->getPluginLoader(self::DECORATOR), $options); if (!empty($this->_displayGroupPrefixPaths)) { $this->_displayGroups[$name]->addPrefixPaths($this->_displayGroupPrefixPaths); } $this->_order[$name] = $this->_displayGroups[$name]->getOrder(); $this->_orderUpdated = true; return $this; }
/** * Factory method to fetch what you want to work with. * * @param string $section Create the method that you want to work with * @param string $key Override the default aws key * @param string $secret_key Override the default aws secretkey * @throws Zend\Service\Amazon\Ec2\Exception * @return object */ public static function factory($section, $key = null, $secret_key = null) { switch (strtolower($section)) { case 'keypair': $class = '\\Zend\\Service\\Amazon\\Ec2\\Keypair'; break; case 'eip': // break left out // break left out case 'elasticip': $class = '\\Zend\\Service\\Amazon\\Ec2\\ElasticIp'; break; case 'ebs': $class = '\\Zend\\Service\\Amazon\\Ec2\\Ebs'; break; case 'availabilityzones': // break left out // break left out case 'zones': $class = '\\Zend\\Service\\Amazon\\Ec2\\AvailabilityZones'; break; case 'ami': // break left out // break left out case 'image': $class = '\\Zend\\Service\\Amazon\\Ec2\\Image'; break; case 'instance': $class = '\\Zend\\Service\\Amazon\\Ec2\\Instance'; break; case 'security': // break left out // break left out case 'securitygroups': $class = '\\Zend\\Service\\Amazon\\Ec2\\SecurityGroups'; break; default: throw new Exception\RuntimeException('Invalid Section: ' . $section); break; } if (!class_exists($class)) { \Zend\Loader::loadClass($class); } return new $class($key, $secret_key); }
/** * Returns the current adapter, instantiating it if necessary * * @return string */ public function getAdapter() { if ($this->_adapter instanceof Compress\CompressionAlgorithm) { return $this->_adapter; } $adapter = $this->_adapter; $options = $this->getAdapterOptions(); if (!class_exists($adapter)) { if (\Zend\Loader::isReadable('Zend/Filter/Compress/' . ucfirst($adapter) . '.php')) { $adapter = 'Zend\\Filter\\Compress\\' . ucfirst($adapter); } \Zend\Loader::loadClass($adapter); } $this->_adapter = new $adapter($options); if (!$this->_adapter instanceof Compress\CompressionAlgorithm) { throw new Exception\InvalidArgumentException("Compression adapter '" . $adapter . "' does not implement Zend\\Filter\\Compress\\CompressionAlgorithm"); } return $this->_adapter; }
/** * Set the class name to use for the default registry instance. * Does not affect the currently initialized instance, it only applies * for the next time you instantiate. * * @param string $registryClassName * @return void * @throws RuntimeException if the registry is initialized or if the * class name is not valid. */ public static function setClassName($registryClassName = 'Zend\\Registry') { if (self::$registry !== null) { throw new RuntimeException('Registry is already initialized'); } if (!is_string($registryClassName)) { throw new RuntimeException("Argument is not a class name"); } /** * @see Zend\\Loader */ if (!class_exists($registryClassName)) { Loader::loadClass($registryClassName); } self::$registryClassName = $registryClassName; }
/** * Set the container class to use * * @param string $name * @return \Zend\View\Helper\Placeholder\Registry */ public function setContainerClass($name) { if (!class_exists($name)) { \Zend\Loader::loadClass($name); } if (!in_array('Zend\View\Helper\Placeholder\Container\AbstractContainer', class_parents($name))) { $e = new Container\Exception('Invalid Container class specified'); throw $e; } $this->_containerClass = $name; return $this; }
/** * Get session object * * @return \Zend\Session\Container */ public function getSession() { if (!isset($this->_session) || null === $this->_session) { $id = $this->getId(); if (!class_exists($this->_sessionClass)) { \Zend\Loader::loadClass($this->_sessionClass); } $this->_session = new $this->_sessionClass('Zend_Form_Captcha_' . $id); $this->_session->setExpirationHops(1, null, true); $this->_session->setExpirationSeconds($this->getTimeout()); } return $this->_session; }