import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -0,0 +1,201 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Profile
*/
require_once 'Zend/Tool/Project/Profile.php';
/**
* @see Zend_Tool_Framework_Provider_Abstract
*/
require_once 'Zend/Tool/Framework/Provider/Abstract.php';
/**
* @see Zend_Tool_Project_Context_Repository
*/
require_once 'Zend/Tool/Project/Context/Repository.php';
/**
* @see Zend_Tool_Project_Profile_FileParser_Xml
*/
require_once 'Zend/Tool/Project/Profile/FileParser/Xml.php';
/**
* @see Zend_Tool_Framework_Registry
*/
require_once 'Zend/Tool/Framework/Registry.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Tool_Project_Provider_Abstract extends Zend_Tool_Framework_Provider_Abstract
{
const NO_PROFILE_THROW_EXCEPTION = true;
const NO_PROFILE_RETURN_FALSE = false;
/**
* @var bool
*/
protected static $_isInitialized = false;
protected $_projectPath = null;
/**
* @var Zend_Tool_Project_Profile
*/
protected $_loadedProfile = null;
/**
* constructor
*
* YOU SHOULD NOT OVERRIDE THIS, unless you know what you are doing
*
*/
public function __construct()
{
// initialize the ZF Contexts (only once per php request)
if (!self::$_isInitialized) {
$contextRegistry = Zend_Tool_Project_Context_Repository::getInstance();
$contextRegistry->addContextsFromDirectory(
dirname(dirname(__FILE__)) . '/Context/Zf/', 'Zend_Tool_Project_Context_Zf_'
);
self::$_isInitialized = true;
}
// load up the extending providers required context classes
if ($contextClasses = $this->getContextClasses()) {
$this->_loadContextClassesIntoRegistry($contextClasses);
}
}
public function getContextClasses()
{
return array();
}
/**
* _getProject is designed to find if there is project file in the context of where
* the client has been called from.. The search order is as follows..
* - traversing downwards from (PWD) - current working directory
* - if an enpoint variable has been registered in teh client registry - key=workingDirectory
* - if an ENV variable with the key ZFPROJECT_PATH is found
*
* @
* @return Zend_Tool_Project_Profile
*/
protected function _loadProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION, $projectDirectory = null)
{
if ($projectDirectory == null) {
$projectDirectory = getcwd();
}
$profile = new Zend_Tool_Project_Profile();
$profile->setAttribute('projectDirectory', $projectDirectory);
if ($profile->isLoadableFromFile()) {
$profile->loadFromFile();
$this->_loadedProfile = $profile;
}
if ($this->_loadedProfile == null) {
if ($loadProfileFlag == self::NO_PROFILE_THROW_EXCEPTION) {
throw new Zend_Tool_Project_Provider_Exception('A project profile was not found.');
} elseif ($loadProfileFlag == self::NO_PROFILE_RETURN_FALSE) {
return false;
}
}
return $profile;
}
/**
* Load the project profile from the current working directory, if not throw exception
*
* @return Zend_Tool_Project_Profile
*/
protected function _loadProfileRequired()
{
$profile = $this->_loadProfile();
if ($profile === false) {
require_once 'Zend/Tool/Project/Provider/Exception.php';
throw new Zend_Tool_Project_Provider_Exception('A project profile was not found in the current working directory.');
}
return $profile;
}
/**
* Return the currently loaded profile
*
* @return Zend_Tool_Project_Profile
*/
protected function _getProfile($loadProfileFlag = self::NO_PROFILE_THROW_EXCEPTION)
{
if (!$this->_loadedProfile) {
if (($this->_loadProfile($loadProfileFlag) === false) && ($loadProfileFlag === self::NO_PROFILE_RETURN_FALSE)) {
return false;
}
}
return $this->_loadedProfile;
}
/**
* _storeProfile()
*
* This method will store the profile into its proper location
*
*/
protected function _storeProfile()
{
$projectProfileFile = $this->_loadedProfile->search('ProjectProfileFile');
$name = $projectProfileFile->getContext()->getPath();
$this->_registry->getResponse()->appendContent('Updating project profile \'' . $name . '\'');
$projectProfileFile->getContext()->save();
}
/**
* _loadContextClassesIntoRegistry() - This is called by the constructor
* so that child providers can provide a list of contexts to load into the
* context repository
*
* @param array $contextClasses
*/
private function _loadContextClassesIntoRegistry($contextClasses)
{
$registry = Zend_Tool_Project_Context_Repository::getInstance();
foreach ($contextClasses as $contextClass) {
$registry->addContextClass($contextClass);
}
}
}

View File

@ -0,0 +1,168 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @see Zend_Tool_Framework_Provider_Pretendable
*/
require_once 'Zend/Tool/Framework/Provider/Pretendable.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Action
extends Zend_Tool_Project_Provider_Abstract
implements Zend_Tool_Framework_Provider_Pretendable
{
/**
* createResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $actionName
* @param string $controllerName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function createResource(Zend_Tool_Project_Profile $profile, $actionName, $controllerName, $moduleName = null)
{
if (!is_string($actionName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Action::createResource() expects \"actionName\" is the name of a action resource to create.');
}
if (!is_string($controllerName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Action::createResource() expects \"controllerName\" is the name of a controller resource to create.');
}
$controllerFile = self::_getControllerFileResource($profile, $controllerName, $moduleName);
$actionMethod = $controllerFile->createResource('ActionMethod', array('actionName' => $actionName));
return $actionMethod;
}
/**
* hasResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $actionName
* @param string $controllerName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function hasResource(Zend_Tool_Project_Profile $profile, $actionName, $controllerName, $moduleName = null)
{
if (!is_string($actionName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Action::createResource() expects \"actionName\" is the name of a action resource to create.');
}
if (!is_string($controllerName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Action::createResource() expects \"controllerName\" is the name of a controller resource to create.');
}
$controllerFile = self::_getControllerFileResource($profile, $controllerName, $moduleName);
return (($controllerFile->search(array('actionMethod' => array('actionName' => $actionName)))) instanceof Zend_Tool_Project_Profile_Resource);
}
/**
* _getControllerFileResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $controllerName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
protected static function _getControllerFileResource(Zend_Tool_Project_Profile $profile, $controllerName, $moduleName = null)
{
$profileSearchParams = array();
if ($moduleName != null && is_string($moduleName)) {
$profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
}
$profileSearchParams[] = 'controllersDirectory';
$profileSearchParams['controllerFile'] = array('controllerName' => $controllerName);
return $profile->search($profileSearchParams);
}
/**
* create()
*
* @param string $name
* @param string $controllerName
* @param bool $viewIncluded
*/
public function create($name, $controllerName = 'index', $viewIncluded = true, $module = null)
{
$this->_loadProfile();
if (self::hasResource($this->_loadedProfile, $name, $controllerName, $module)) {
throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')');
}
$actionMethod = self::createResource($this->_loadedProfile, $name, $controllerName, $module);
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse()->appendContent(
'Would create an action named ' . $name .
' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath()
);
} else {
$this->_registry->getResponse()->appendContent(
'Creating an action named ' . $name .
' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath()
);
$actionMethod->create();
$this->_storeProfile();
}
if ($viewIncluded) {
$viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, $controllerName, $module);
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse()->appendContent(
'Would create a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath()
);
} else {
$this->_registry->getResponse()->appendContent(
'Creating a view script for the ' . $name . ' action method at ' . $viewResource->getContext()->getPath()
);
$viewResource->create();
$this->_storeProfile();
}
}
}
}

View File

@ -0,0 +1,199 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @see Zend_Tool_Framework_Registry
*/
require_once 'Zend/Tool/Framework/Registry.php';
/**
* @see Zend_Tool_Project_Provider_View
*/
require_once 'Zend/Tool/Project/Provider/View.php';
/**
* @see Zend_Tool_Project_Provider_Exception
*/
require_once 'Zend/Tool/Project/Provider/Exception.php';
/**
* @see Zend_Tool_Framework_Provider_Pretendable
*/
require_once 'Zend/Tool/Framework/Provider/Pretendable.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Controller
extends Zend_Tool_Project_Provider_Abstract
implements Zend_Tool_Framework_Provider_Pretendable
{
/**
* createResource will create the controllerFile resource at the appropriate location in the
* profile. NOTE: it is your job to execute the create() method on the resource, as well as
* store the profile when done.
*
* @param Zend_Tool_Project_Profile $profile
* @param string $controllerName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function createResource(Zend_Tool_Project_Profile $profile, $controllerName, $moduleName = null)
{
if (!is_string($controllerName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Controller::createResource() expects \"controllerName\" is the name of a controller resource to create.');
}
if (!($controllersDirectory = self::_getControllersDirectoryResource($profile, $moduleName))) {
if ($moduleName) {
$exceptionMessage = 'A controller directory for module "' . $moduleName . '" was not found.';
} else {
$exceptionMessage = 'A controller directory was not found.';
}
throw new Zend_Tool_Project_Provider_Exception($exceptionMessage);
}
$newController = $controllersDirectory->createResource('controllerFile', array('controllerName' => $controllerName));
return $newController;
}
/**
* hasResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $controllerName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function hasResource(Zend_Tool_Project_Profile $profile, $controllerName, $moduleName = null)
{
if (!is_string($controllerName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Controller::createResource() expects \"controllerName\" is the name of a controller resource to create.');
}
$controllersDirectory = self::_getControllersDirectoryResource($profile, $moduleName);
return (($controllersDirectory->search(array('controllerFile' => array('controllerName' => $controllerName)))) instanceof Zend_Tool_Project_Profile_Resource);
}
/**
* _getControllersDirectoryResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
protected static function _getControllersDirectoryResource(Zend_Tool_Project_Profile $profile, $moduleName = null)
{
$profileSearchParams = array();
if ($moduleName != null && is_string($moduleName)) {
$profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
}
$profileSearchParams[] = 'controllersDirectory';
return $profile->search($profileSearchParams);
}
/**
* Enter description here...
*
* @param string $name The name of the controller to create.
* @param bool $indexActionIncluded Whether or not to create the index action.
*/
public function create($name, $indexActionIncluded = true, $module = null)
{
$this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
// determine if testing is enabled in the project
require_once 'Zend/Tool/Project/Provider/Test.php';
$testingEnabled = Zend_Tool_Project_Provider_Test::isTestingEnabled($this->_loadedProfile);
if (self::hasResource($this->_loadedProfile, $name, $module)) {
throw new Zend_Tool_Project_Provider_Exception('This project already has a controller named ' . $name);
}
try {
$controllerResource = self::createResource($this->_loadedProfile, $name, $module);
if ($indexActionIncluded) {
$indexActionResource = Zend_Tool_Project_Provider_Action::createResource($this->_loadedProfile, 'index', $name, $module);
$indexActionViewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, 'index', $name, $module);
}
if ($testingEnabled) {
$testControllerResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $name, 'index', $module);
}
} catch (Exception $e) {
$response = $this->_registry->getResponse();
$response->setException($e);
return;
}
// do the creation
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse()->appendContent('Would create a controller at ' . $controllerResource->getContext()->getPath());
if (isset($indexActionResource)) {
$this->_registry->getResponse()->appendContent('Would create an index action method in controller ' . $name);
$this->_registry->getResponse()->appendContent('Would create a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
}
if ($testControllerResource) {
$this->_registry->getResponse()->appendContent('Would create a controller test file at ' . $testControllerResource->getContext()->getPath());
}
} else {
$this->_registry->getResponse()->appendContent('Creating a controller at ' . $controllerResource->getContext()->getPath());
$controllerResource->create();
if (isset($indexActionResource)) {
$this->_registry->getResponse()->appendContent('Creating an index action method in controller ' . $name);
$indexActionResource->create();
$this->_registry->getResponse()->appendContent('Creating a view script for the index action method at ' . $indexActionViewResource->getContext()->getPath());
$indexActionViewResource->create();
}
if ($testControllerResource) {
$this->_registry->getResponse()->appendContent('Creating a controller test file at ' . $testControllerResource->getContext()->getPath());
$testControllerResource->create();
}
$this->_storeProfile();
}
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Exception
*/
require_once 'Zend/Tool/Project/Exception.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Exception extends Zend_Tool_Project_Exception
{
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Form extends Zend_Tool_Project_Provider_Abstract
{
public function create($name)
{
echo '@todo - create form';
}
}

View File

@ -0,0 +1,90 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Framework_Manifest_ProviderManifestable
*/
require_once 'Zend/Tool/Framework/Manifest/ProviderManifestable.php';
/**
* @see Zend_Tool_Project_Provider_Profile
*/
require_once 'Zend/Tool/Project/Provider/Profile.php';
/**
* @see Zend_Tool_Project_Provider_Project
*/
require_once 'Zend/Tool/Project/Provider/Project.php';
/**
* @see Zend_Tool_Project_Provider_Controller
*/
require_once 'Zend/Tool/Project/Provider/Controller.php';
/**
* @see Zend_Tool_Project_Provider_Action
*/
require_once 'Zend/Tool/Project/Provider/Action.php';
/**
* @see Zend_Tool_Project_Provider_View
*/
require_once 'Zend/Tool/Project/Provider/View.php';
/**
* @see Zend_Tool_Project_Provider_Module
*/
require_once 'Zend/Tool/Project/Provider/Module.php';
/**
* @see Zend_Tool_Project_Provider_ProjectProvider
*/
require_once 'Zend/Tool/Project/Provider/ProjectProvider.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Manifest implements
Zend_Tool_Framework_Manifest_ProviderManifestable
{
/**
* getProviders()
*
* @return array Array of Providers
*/
public function getProviders()
{
return array(
new Zend_Tool_Project_Provider_Profile(),
new Zend_Tool_Project_Provider_Project(),
new Zend_Tool_Project_Provider_Controller(),
new Zend_Tool_Project_Provider_Action(),
new Zend_Tool_Project_Provider_View(),
new Zend_Tool_Project_Provider_Module(),
new Zend_Tool_Project_Provider_ProjectProvider()
);
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Model extends Zend_Tool_Project_Provider_Abstract
{
/**
* create()
*
* @param string $name
*/
public function create($name)
{
echo '@todo - create model';
}
}

View File

@ -0,0 +1,165 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @see Zend_Tool_Framework_Provider_Pretendable
*/
require_once 'Zend/Tool/Framework/Provider/Pretendable.php';
/**
* @see Zend_Tool_Project_Profile_Iterator_ContextFilter
*/
require_once 'Zend/Tool/Project/Profile/Iterator/ContextFilter.php';
/**
* @see Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter
*/
require_once 'Zend/Tool/Project/Profile/Iterator/EnabledResourceFilter.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Module
extends Zend_Tool_Project_Provider_Abstract
implements Zend_Tool_Framework_Provider_Pretendable
{
public static function createResources(Zend_Tool_Project_Profile $profile, $moduleName, Zend_Tool_Project_Profile_Resource $targetModuleResource = null)
{
// find the appliction directory, it will serve as our module skeleton
if ($targetModuleResource == null) {
$targetModuleResource = $profile->search('applicationDirectory');
$targetModuleEnabledResources = array(
'ControllersDirectory', 'ModelsDirectory', 'ViewsDirectory',
'ViewScriptsDirectory', 'ViewHelpersDirectory', 'ViewFiltersDirectory'
);
}
// find the actual modules directory we will use to house our module
$modulesDirectory = $profile->search('modulesDirectory');
// if there is a module directory already, except
if ($modulesDirectory->search(array('moduleDirectory' => array('moduleName' => $moduleName)))) {
throw new Zend_Tool_Project_Provider_Exception('A module named "' . $moduleName . '" already exists.');
}
// create the module directory
$moduleDirectory = $modulesDirectory->createResource('moduleDirectory', array('moduleName' => $moduleName));
// create a context filter so that we can pull out only what we need from the module skeleton
$moduleContextFilterIterator = new Zend_Tool_Project_Profile_Iterator_ContextFilter(
$targetModuleResource,
array(
'denyNames' => array('ModulesDirectory', 'ViewControllerScriptsDirectory'),
'denyType' => 'Zend_Tool_Project_Context_Filesystem_File'
)
);
// the iterator for the module skeleton
$targetIterator = new RecursiveIteratorIterator($moduleContextFilterIterator, RecursiveIteratorIterator::SELF_FIRST);
// initialize some loop state information
$currentDepth = 0;
$parentResources = array();
$currentResource = $moduleDirectory;
// loop through the target module skeleton
foreach ($targetIterator as $targetSubResource) {
$depthDifference = $targetIterator->getDepth() - $currentDepth;
$currentDepth = $targetIterator->getDepth();
if ($depthDifference === 1) {
// if we went down into a child, make note
array_push($parentResources, $currentResource);
// this will have always been set previously by another loop
$currentResource = $currentChildResource;
} elseif ($depthDifference < 0) {
// if we went up to a parent, make note
$i = $depthDifference;
do {
// if we went out more than 1 parent, get to the correct parent
$currentResource = array_pop($parentResources);
} while ($i-- > 0);
}
// get parameters for the newly created module resource
$params = $targetSubResource->getAttributes();
$currentChildResource = $currentResource->createResource($targetSubResource->getName(), $params);
// based of the provided list (Currently up top), enable specific resources
if (isset($targetModuleEnabledResources)) {
$currentChildResource->setEnabled(in_array($targetSubResource->getName(), $targetModuleEnabledResources));
} else {
$currentChildResource->setEnabled($targetSubResource->isEnabled());
}
}
return $moduleDirectory;
}
/**
* create()
*
* @param string $name
*/
public function create($name) //, $moduleProfile = null)
{
$this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
$resources = self::createResources($this->_loadedProfile, $name);
$response = $this->_registry->getResponse();
if ($this->_registry->getRequest()->isPretend()) {
$response->appendContent('I would create the following module and artifacts:');
foreach (new RecursiveIteratorIterator($resources, RecursiveIteratorIterator::SELF_FIRST) as $resource) {
if (is_callable(array($resource->getContext(), 'getPath'))) {
$response->appendContent($resource->getContext()->getPath());
}
}
} else {
$response->appendContent('Creating the following module and artifacts:');
$enabledFilter = new Zend_Tool_Project_Profile_Iterator_EnabledResourceFilter($resources);
foreach (new RecursiveIteratorIterator($enabledFilter, RecursiveIteratorIterator::SELF_FIRST) as $resource) {
$response->appendContent($resource->getContext()->getPath());
$resource->create();
}
// store changes to the profile
$this->_storeProfile();
}
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Profile extends Zend_Tool_Project_Provider_Abstract
{
/**
* show()
*
*/
public function show()
{
$this->_loadProfile();
$profileIterator = $this->_loadedProfile->getIterator();
foreach ($profileIterator as $profileItem) {
$this->_registry->getResponse()->appendContent(
str_repeat(' ', $profileIterator->getDepth()) . $profileItem
);
}
}
}

View File

@ -0,0 +1,148 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Project extends Zend_Tool_Project_Provider_Abstract
{
/**
* create()
*
* @param string $path
*/
public function create($path)
{
if ($path == null) {
$path = getcwd();
} else {
$path = trim($path);
if (!file_exists($path)) {
$created = mkdir($path);
if (!$created) {
require_once 'Zend/Tool/Framework/Client/Exception.php';
throw new Zend_Tool_Framework_Client_Exception('Could not create requested project directory \'' . $path . '\'');
}
}
$path = str_replace('\\', '/', realpath($path));
}
$profile = $this->_loadProfile(self::NO_PROFILE_RETURN_FALSE, $path);
if ($profile !== false) {
require_once 'Zend/Tool/Framework/Client/Exception.php';
throw new Zend_Tool_Framework_Client_Exception('A project already exists here');
}
$newProfile = new Zend_Tool_Project_Profile(array(
'projectDirectory' => $path,
'profileData' => $this->_getDefaultProfile()
));
$newProfile->loadFromData();
$this->_registry->getResponse()->appendContent('Creating project at ' . $path);
foreach ($newProfile->getIterator() as $resource) {
$resource->create();
}
}
protected function _getDefaultProfile()
{
$data = <<<EOS
<?xml version="1.0" encoding="UTF-8"?>
<projectProfile type="default">
<projectDirectory>
<projectProfileFile />
<applicationDirectory>
<apisDirectory enabled="false" />
<configsDirectory>
<applicationConfigFile type="ini" />
</configsDirectory>
<controllersDirectory>
<controllerFile controllerName="index">
<actionMethod actionName="index" />
</controllerFile>
<controllerFile controllerName="error" />
</controllersDirectory>
<layoutsDirectory enabled="false" />
<modelsDirectory />
<modulesDirectory enabled="false" />
<viewsDirectory>
<viewScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="index">
<viewScriptFile forActionName="index" />
</viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="error">
<viewScriptFile forActionName="error" />
</viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory />
<viewFiltersDirectory enabled="false" />
</viewsDirectory>
<bootstrapFile />
</applicationDirectory>
<dataDirectory enabled="false">
<cacheDirectory enabled="false" />
<searchIndexesDirectory enabled="false" />
<localesDirectory enabled="false" />
<logsDirectory enabled="false" />
<sessionsDirectory enabled="false" />
<uploadsDirectory enabled="false" />
</dataDirectory>
<libraryDirectory>
<zfStandardLibraryDirectory enabled="false" />
</libraryDirectory>
<publicDirectory>
<publicStylesheetsDirectory enabled="false" />
<publicScriptsDirectory enabled="false" />
<publicImagesDirectory enabled="false" />
<publicIndexFile />
<htaccessFile />
</publicDirectory>
<projectProvidersDirectory enabled="false" />
<temporaryDirectory enabled="false" />
<testsDirectory>
<testPHPUnitConfigFile />
<testApplicationDirectory>
<testApplicationBootstrapFile />
</testApplicationDirectory>
<testLibraryDirectory>
<testLibraryBootstrapFile />
</testLibraryDirectory>
</testsDirectory>
</projectDirectory>
</projectProfile>
EOS;
return $data;
}
}

View File

@ -0,0 +1,99 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Tool_Project_Provider_Abstract */
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/** Zend_Tool_Project_Provider_Exception */
require_once 'Zend/Tool/Project/Provider/Exception.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_ProjectProvider extends Zend_Tool_Project_Provider_Abstract
{
/**
* createResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $projectProviderName
* @param string $actionNames
* @return Zend_Tool_Project_Profile_Resource
*/
public static function createResource(Zend_Tool_Project_Profile $profile, $projectProviderName, $actionNames = null)
{
if (!is_string($projectProviderName)) {
/**
* @see Zend_Tool_Project_Provider_Exception
*/
require_once 'Zend/Tool/Project/Provider/Exception.php';
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_Controller::createResource() expects \"projectProviderName\" is the name of a project provider resource to create.');
}
$profileSearchParams = array();
$profileSearchParams[] = 'projectProvidersDirectory';
$projectProvider = $profile->createResourceAt($profileSearchParams, 'projectProviderFile', array('projectProviderName' => $projectProviderName, 'actionNames' => $actionNames));
return $projectProvider;
}
/**
* getName()
*
* @return string
*/
public function getName()
{
return 'ProjectProvider';
}
/**
* Create stub for Zend_Tool Project Provider
*
* @var string $name class name for new Zend_Tool Project Provider
* @var array|string $actions list of provider methods
* @throws Zend_Tool_Project_Provider_Exception
*/
public function create($name, $actions = null)
{
$profile = $this->_loadProfileRequired();
$projectProvider = self::createResource($profile, $name, $actions);
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse()->appendContent('Would create a project provider named ' . $name
. ' in location ' . $projectProvider->getPath()
);
} else {
$this->_registry->getResponse()->appendContent('Creating a project provider named ' . $name
. ' in location ' . $projectProvider->getPath()
);
$projectProvider->create();
$this->_storeProfile();
}
}
}

View File

@ -0,0 +1,174 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @see Zend_Tool_Project_Provider_Exception
*/
require_once 'Zend/Tool/Project/Provider/Exception.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_Test extends Zend_Tool_Project_Provider_Abstract
{
protected $_specialties = array('Application', 'Library');
/**
* isTestingEnabled()
*
* @param Zend_Tool_Project_Profile $profile
* @return bool
*/
public static function isTestingEnabled(Zend_Tool_Project_Profile $profile)
{
$profileSearchParams = array('testsDirectory');
$testsDirectory = $profile->search($profileSearchParams);
return $testsDirectory->isEnabled();
}
/**
* createApplicationResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $controllerName
* @param string $actionName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function createApplicationResource(Zend_Tool_Project_Profile $profile, $controllerName, $actionName, $moduleName = null)
{
if (!is_string($controllerName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createApplicationResource() expects \"controllerName\" is the name of a controller resource to create.');
}
if (!is_string($actionName)) {
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createApplicationResource() expects \"actionName\" is the name of a controller resource to create.');
}
$testsDirectoryResource = $profile->search('testsDirectory');
if (($testAppDirectoryResource = $testsDirectoryResource->search('testApplicationDirectory')) === false) {
$testAppDirectoryResource = $testsDirectoryResource->createResource('testApplicationDirectory');
}
if ($moduleName) {
//@todo $moduleName
$moduleName = '';
}
if (($testAppControllerDirectoryResource = $testAppDirectoryResource->search('testApplicationControllerDirectory')) === false) {
$testAppControllerDirectoryResource = $testAppDirectoryResource->createResource('testApplicationControllerDirectory');
}
$testAppControllerFileResource = $testAppControllerDirectoryResource->createResource('testApplicationControllerFile', array('forControllerName' => $controllerName));
return $testAppControllerFileResource;
}
/**
* createLibraryResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $libraryClassName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function createLibraryResource(Zend_Tool_Project_Profile $profile, $libraryClassName)
{
$testLibraryDirectoryResource = $profile->search(array('TestsDirectory', 'TestLibraryDirectory'));
$fsParts = explode('_', $libraryClassName);
$currentDirectoryResource = $testLibraryDirectoryResource;
while ($nameOrNamespacePart = array_shift($fsParts)) {
if (count($fsParts) > 0) {
if (($libraryDirectoryResource = $currentDirectoryResource->search(array('TestLibraryNamespaceDirectory' => array('namespaceName' => $nameOrNamespacePart)))) === false) {
$currentDirectoryResource = $currentDirectoryResource->createResource('TestLibraryNamespaceDirectory', array('namespaceName' => $nameOrNamespacePart));
} else {
$currentDirectoryResource = $libraryDirectoryResource;
}
} else {
if (($libraryFileResource = $currentDirectoryResource->search(array('TestLibraryFile' => array('forClassName' => $libraryClassName)))) === false) {
$libraryFileResource = $currentDirectoryResource->createResource('TestLibraryFile', array('forClassName' => $libraryClassName));
}
}
}
return $libraryFileResource;
}
public function enable()
{
}
public function disable()
{
}
/**
* create()
*
* @param unknown_type $libraryClassName
*/
public function create($libraryClassName)
{
$profile = $this->_loadProfile();
if (!self::isTestingEnabled($profile)) {
$this->_registry->getResponse()->appendContent('Testing is not enabled for this project.');
}
$testLibraryResource = self::createLibraryResource($profile, $libraryClassName);
$response = $this->_registry->getResponse();
if ($this->_registry->getRequest()->isPretend()) {
$response->appendContent('Would create a library stub in location ' . $testLibraryResource->getContext()->getPath());
} else {
$response->appendContent('Creating a library stub in location ' . $testLibraryResource->getContext()->getPath());
$testLibraryResource->create();
$this->_storeProfile();
}
}
}

View File

@ -0,0 +1,118 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Tool
* @subpackage Framework
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/
/**
* @see Zend_Tool_Project_Provider_Abstract
*/
require_once 'Zend/Tool/Project/Provider/Abstract.php';
/**
* @category Zend
* @package Zend_Tool
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Tool_Project_Provider_View extends Zend_Tool_Project_Provider_Abstract
{
/**
* createResource()
*
* @param Zend_Tool_Project_Profile $profile
* @param string $actionName
* @param string $controllerName
* @param string $moduleName
* @return Zend_Tool_Project_Profile_Resource
*/
public static function createResource(Zend_Tool_Project_Profile $profile, $actionName, $controllerName, $moduleName = null)
{
if (!is_string($actionName)) {
require_once 'Zend/Tool/Project/Provider/Exception.php';
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"actionName\" is the name of a controller resource to create.');
}
if (!is_string($controllerName)) {
require_once 'Zend/Tool/Project/Provider/Exception.php';
throw new Zend_Tool_Project_Provider_Exception('Zend_Tool_Project_Provider_View::createResource() expects \"controllerName\" is the name of a controller resource to create.');
}
$profileSearchParams = array();
if ($moduleName) {
$profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
$noModuleSearch = null;
} else {
$noModuleSearch = array('ModulesDirectory');
}
$profileSearchParams[] = 'viewsDirectory';
$profileSearchParams[] = 'viewScriptsDirectory';
if (($viewScriptsDirectory = $profile->search($profileSearchParams, $noModuleSearch)) === false) {
require_once 'Zend/Tool/Project/Provider/Exception.php';
throw new Zend_Tool_Project_Provider_Exception('This project does not have a viewScriptsDirectory resource.');
}
$profileSearchParams['viewControllerScriptsDirectory'] = array('forControllerName' => $controllerName);
// XXXXXXXXX below is failing b/c of above search params
if (($viewControllerScriptsDirectory = $viewScriptsDirectory->search($profileSearchParams)) === false) {
$viewControllerScriptsDirectory = $viewScriptsDirectory->createResource('viewControllerScriptsDirectory', array('forControllerName' => $controllerName));
}
$newViewScriptFile = $viewControllerScriptsDirectory->createResource('ViewScriptFile', array('forActionName' => $actionName));
return $newViewScriptFile;
}
/**
* create()
*
* @param string $controllerName
* @param string $actionNameOrSimpleName
*/
public function create($controllerName, $actionNameOrSimpleName)
{
if ($controllerName == '' || $actionNameOrSimpleName == '') {
require_once 'Zend/Tool/Project/Provider/Exception.php';
throw new Zend_Tool_Project_Provider_Exception('ControllerName and/or ActionName are empty.');
}
$profile = $this->_loadProfile();
$view = self::createResource($profile, $actionNameOrSimpleName, $controllerName);
if ($this->_registry->getRequest()->isPretend()) {
$this->_registry->getResponse(
'Would create a view script in location ' . $view->getContext()->getPath()
);
} else {
$this->_registry->getResponse(
'Creating a view script in location ' . $view->getContext()->getPath()
);
$view->create();
$this->_storeProfile();
}
}
}