View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template With Tracker}

{zone-data:jira-key}ZFENV{zone-data}
{zone-data:jira-pid}10022{zone-data}
{zone-data:jira-recently}
{jiraissues:url=http://framework.zend.com/issues/secure/IssueNavigator.jspa?view=rss&created%3Aprevious=-1w&pid=10022&sorter/field=created&sorter/order=DESC&tempMax=25&reset=true&decorator=none|columns=Type;Key;Summary;Assignee;Priority;Status;Created}
{zone-data}
{zone-data:jira-summary}
{jiraportlet:url=http://framework.zend.com/issues/secure/RunPortlet.jspa?portletKey=com.atlassian.jira.plugin.system.portlets:project&projectid=10022&projectinfo=full}
{zone-data}
{zone-data:review-end}August 27, 2006{zone-data}

{zone-data:component-name}
Zend_Environment
{zone-data}

{zone-data:proposer-list}
[~peptolab]
[Alexander Veremyev (Zend Liaison)|~alexander]
{zone-data}

{zone-data:revision}
0.1 - 30 June 2006: Initial proposal.
0.2 - 3 July 2007: Revised proposal with 2 new methods.
{zone-data}

{zone-data:overview}
Zend_Environment provides a singular method for obtaining supplementary information on PHP, PHP Modules and other environmental settings
{zone-data}

{zone-data:references}
* [phpInfo()|http://php.net/manual/en/function.phpinfo.php#59573]
{zone-data}

{zone-data:requirements}
* Gathers output from phpInfo() and stores as an associative array
* Provides per-section and/or per-module information from phpInfo()
* Provides OS information as associative array
* Provides list of currently loaded extensions or tests for existence of specific extension
* Provides a module interface to allow further extensions (e.g. security)
{zone-data}

{zone-data:dependencies}
* Zend_Exception
{zone-data}

{zone-data:operation}
A Zend_Environment instance is created by passing one or more Zend_Environment_Module instances to the constructor. The object then parses each module (according to that module's own interpreter) and builds a profile of 'section/module' information.

Currently it retrieves only php-related information, but will be used in the future to gather runtime information on the Zend Framework itself (versions installed, etc) or any other supplementary info that would assist developers during testing/debugging. It could also be used as a diagnostic during install processes for self-installing applications (e.g. checkModule() for modules/php/etc).

Each module that is passed to the Zend_Environment is iterable and allows further inspection of each of the modules contained. The common object returned from a module query is a Zend_Environment_Info, which will always return the following properties (which are set at the discretion of each module):-

{code}
$info->title e.g. Session
$info->description e.g. Sessions should only use cookie-based.... etc...
$info->value e.g. $_SESSION...
$info->warning e.g. array('Your time limit is high');
$info->notice
$info->link e.g. http://www.php.net/manual/en/
{code}

{zone-data}

{zone-data:class-list}
* Zend_Environment
* Zend_Environment_Exception
* Zend_Environment_Info
* Zend_Environment_Module_Abstract
* Zend_Environment_Module_Core
* Zend_Environment_Module_Os
* Zend_Environment_Module_Extension
* Zend_Environment_Module_Server
* Zend_Environment_Module_Ini
* Zend_Environment_Decorator_Interface
* Zend_Environment_Decorator_Text
* Zend_Environment_Decorator_Html
* Zend_Environment_Decorator_File
{zone-data}

{zone-data:milestones}
* Milestone 1: Create prototype with 'core' modules - Ini, Core, Extension, Os - Currently in progress as of 20th Sep 2006
* Milestone 2: Develop, refine and finalise with feedback from community and Zend
* Milestone 3: Commit to Incubator, include simple demo and use cases [
* Milestone 4: Unit tests exist, work, and are checked into SVN
* Milestone 5: Commit initial documentation
* Milestone 6: Extend modules with Security, Hostinfo (tbc) - Contingent on Security module completed by Ed Finkler
* Milestone 7: Add localised (localized? :) warnings, info and error messages - Depends on Zend_Translate being finalised
{zone-data}

{zone-data:use-cases}
||UC-01||
{code}
// Retrieve required modules
$extensions = new Zend_Environment_Module_Extension();
$security = new Zend_Environment_Module_Os();
$ini = new Zend_Environment_Module_Ini();

// Construct environment
$environment = new Zend_Environment(array($extensions,
$security,
$ini));

// Determine current server environment - useful for Zend_Config
$location = $environment->getHostId(array('live' => array('www.mysite.com',
'123.123.123.123'),
'staging' => '*.mysite.com',
'development' => array('127.0.0.1',
'10.0.1.0/24',
'localhost')));
echo "Location: {$location}\n";

// Check section exists
if ($environment->exists('security')) {
echo("Can perform security updates\n");
}

// Check module exists and has valid version
if (!$environment->checkModule('extension', 'gd-2.0.12')) {
throw new exception("I can't run without GD 2.0.12!");
}

// Test module validity
if (!$environment->isValid('os', 'uid')) {
throw new exception("invalid uid");
}

// Output environment to browser
echo $environment->toHtml();

// Output environment to a log file
$environment->toFile('/path/to/your/environment.txt');

// Export environment as an array
print_r($environment->asArray());
{code}
{zone-data}

{zone-data:skeletons}
For class skeletons please see [attached file|http://framework.zend.com/wiki/download/attachments/1157/Environment.zip]
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>