<?php

// This is a compiled Agavi configuration file
// Compiled from: /Users/fgilcher/Sites/agavi/branches/1.0/samples/app/config/animals.xml
// Generated by: AgaviReturnArrayConfigHandler
// Date: 2009-02-17T11:43:38+0000

return array (
  'animals' => 
  array (
    'lolcat' => 
    array (
      'description' => 'Lolcats are a species that evolved on the internet.',
      'fear_factor' => '0',
    ),
    'hippo' => 
    array (
      'description' => 'Although not carnivores, hippos are among the most dangerous creatures encountered. If threatened, they attack viciously, their bite will kill.',
      'fear_factor' => '10',
    ),
  ),
);

?>
<?xml version="1.0" encoding="UTF-8"?>
<ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"; xmlns="http://agavi.org/agavi/config/parts/config_handlers/1.0"; parent="%core.system_config_dir%/config_handlers.xml">
	<ae:configuration>
		<handler pattern="%core.config_dir%/animals.xml" class="AgaviReturnArrayConfigHandler">
			<!--<validation>optional path to an xsd schema file</validation>
			<transformation>optional path to an xsl transformation file</transformation>-->
		</handler>
	</ae:configuration>
</ae:configurations>
<?xml version="1.0" encoding="UTF-8"?>
<configurations xmlns="http://agavi.org/agavi/1.0/config";>
	<configuration>
		<animals>
			<animal name="lolcat">
				<description>Lolcats are a species that evolved on the internet.</description>
				<fear_factor>0</fear_factor>
			</animal>
			<animal name="hippo">
				<description>Although not carnivores, hippos are among the most dangerous creatures encountered. If threatened, they attack viciously, their bite will kill.</description>
				<fear_factor>10</fear_factor>
			</animal>
		</animals>
	</configuration>
	<configuration environment="development">
		<animals>
			<animal name="developer">
				<description>Developers are mainly active at night and shy away from direct sunlight. Their pale skin might look threatening, but in general they are considered harmless.</description>
				<fear_factor>2</fear_factor>
			</animal>
		</animals>
	</configuration>
</configurations>

On Feb 17, 2009, at 11:33 AM, Michal wrote:

On Tue, Feb 17, 2009 at 12:14 AM,  <[email protected]> wrote:
- consider using AgaviReturnArrayConfigHandler

Can I ask how to do this? (Or maybe a pointer to somewhere that explains it?)

Certainly, you can.

The AgaviReturnArrayConfigHandler transforms any XML-Config into a nested array. It's pretty basic and pretty stupid but does the job most of the time. Consider the attached xml. It contains a dataset, could be a configuration etc. I attached the resulting cache file as well as it displays the resulting array.

- The "configuration" node will be the outer array, containing the "animals" array. - Any attribute or inner node "name" will be used as the array key for the elements, this is configurable.
- Any other node will be a key/value pair in the inner elements

The XML contains two configurations - one global and one for the production environment. Unlike some other configuration handlers, the ReturnArrayConfigHandler does not attempt to merge the info. In the development environment, only a single element will be available.

How to use it:

Well, register the config handler in your applications config_handlers.xml. I attache a sample one as well. Then call

$animals = include AgaviConfigCache::checkConfig(AgaviConfig::get('core.config_dir').'/ animals.xml');

and you're done.

Feel free to ask any question that might be left unanswered.


Cheers, felix

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users

Reply via email to