Zend Framework

Allow easy configuration of classResources

Details

  • Type: Patch Patch
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9.6
  • Fix Version/s: None
  • Component/s: Zend_Application
  • Labels:
    None

Description

I have created a patch that allows to configure classResources same as plugins.

Options can be set via the resources configuration, where classResource also can be disabled.
Like:

Bootstrap.php
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initCache()
	{
		$file = $this->getOption('defaultcachedir'). 'pluginLoaderCache.php';
		if (file_exists($file)) {
		    include_once $file;
		}
		if ($this->getOption('plugin')) {
		    Zend_Loader_PluginLoader::setIncludeFileCache($file);
		}
	}

    protected function _initSession() {
    	$session = new Zend_Session_Namespace( $this->getOption('name') );
		Zend_Registry::set( 'session', $session );
		
	    if (!isset($session->initialized)) {
		    Zend_Session::regenerateId();
		    $session->initialized = true;
		}
    }
}

With this config:

<?xml version="1.0"?>
<config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
	<production>		
		<bootstrap>
			<path><zf:const zf:name="APPLICATION_PATH"/>/bootstrap.php</path>
			<class>Bootstrap</class>
		</bootstrap>		
		<phpSettings>
			<display_startup_errors>0</display_startup_errors>
			<display_errors>0</display_errors>
		</phpSettings>
		<resources>
			<frontController>
				<controllerDirectory><zf:const zf:name="APPLICATION_PATH"/>/default/controllers</controllerDirectory>
				<base_url>http://zf.dev</base_url>
			</frontController>
			<db>
				<adapter>PDO_MYSQL</adapter>
				<params>
					<host >localhost</host>
					<username >root</username>
					<password >passw</password>
					<dbname >zf</dbname>
				</params>
				<isDefaultTableAdapter>true</isDefaultTableAdapter>
			</db>
			<cache>
				<defaultcachedir><zf:const zf:name="APPLICATION_PATH"/>/../data/cache/</defaultcachedir>
				<plugin>1</plugin><!-- sets plugin loading -->
				<disabled/><!-- disables whole resource from loading -->
			</cache>
			<session>
				<name>Naam</name>
			</session>
		</resources>
	</production>
</config>

Where _initCache will not be called.

  1. add_resourcemethod_config.patch
    15/Jan/10 1:52 PM
    4 kB
    Michiel Thalen
  2. add_resourcemethod_config.patch
    26/Nov/09 2:13 PM
    4 kB
    Michiel Thalen
  3. add_resourcemethod_config.patch
    26/Nov/09 1:57 PM
    4 kB
    Michiel Thalen
  4. bootstrap_new.php
    27/Nov/09 6:49 AM
    0.6 kB
    Michiel Thalen
  5. bootstrap_old.php
    27/Nov/09 6:49 AM
    0.7 kB
    Michiel Thalen
  6. BootstrapAbstract.patch
    02/Sep/09 2:01 PM
    5 kB
    Michiel Thalen
  7. zf_patch_bm.txt
    27/Nov/09 6:49 AM
    2 kB
    Michiel Thalen
  8. zf_patch_config_new.xml
    27/Nov/09 6:52 AM
    2 kB
    Michiel Thalen
  9. zf_patch_config_old.xml
    27/Nov/09 6:52 AM
    2 kB
    Michiel Thalen

Issue Links

Activity

Hide
Markus added a comment -

I like it

Only thing i dont get: Cache and Session are available Resource Plugins, why not only use this?

But the Disable feature is nice, would like to see this for Res-Plug-Ins too.

Show
Markus added a comment - I like it Only thing i dont get: Cache and Session are available Resource Plugins, why not only use this? But the Disable feature is nice, would like to see this for Res-Plug-Ins too.
Hide
Michiel Thalen added a comment -

Well cache isn't available AFAIK and the session resource doesn't do what this does.
BUT, this is only an example about how it would work.
Resourceplugins you can disable already by just removing them from the resource config.

Show
Michiel Thalen added a comment - Well cache isn't available AFAIK and the session resource doesn't do what this does. BUT, this is only an example about how it would work. Resourceplugins you can disable already by just removing them from the resource config.
Hide
Michiel Thalen added a comment -

updated it

Show
Michiel Thalen added a comment - updated it
Hide
Dolf Schimmel (Freeaqingme) added a comment -

I would personally like to see some benchmarks about this. Though the feature is nice, it's not essential imho, and it has the potential of slowing down every app based on zend_app.

Show
Dolf Schimmel (Freeaqingme) added a comment - I would personally like to see some benchmarks about this. Though the feature is nice, it's not essential imho, and it has the potential of slowing down every app based on zend_app.
Hide
Michiel Thalen added a comment -

I did 2 runs of 10k, results are the patch hardly makes a difference (only a bit faster).
See the attached results and files i ran the test with.

Notice that there is no checking if the options actually exists (so results in a notice error) in the 'old' implementation. An extra check would only make it slower.

Also, since you are saving the config into a local variable, more calls to the getOptions or a bigger config file will make it slower.

Show
Michiel Thalen added a comment - I did 2 runs of 10k, results are the patch hardly makes a difference (only a bit faster). See the attached results and files i ran the test with. Notice that there is no checking if the options actually exists (so results in a notice error) in the 'old' implementation. An extra check would only make it slower. Also, since you are saving the config into a local variable, more calls to the getOptions or a bigger config file will make it slower.

People

Vote (1)
Watch (5)

Dates

  • Created:
    Updated: