Exemplo n.º 1
0
 /**
  * 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 Exception('Zend_Tool_Project_Provider_View::createResource() expects \\"actionName\\" is the name of a controller resource to create.');
     }
     if (!is_string($controllerName)) {
         throw new 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) {
         throw new Exception('This project does not have a viewScriptsDirectory resource.');
     }
     $profileSearchParams['viewControllerScriptsDirectory'] = array('forControllerName' => $controllerName);
     // @todo check if 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;
 }
Exemplo n.º 2
0
 /**
  * _getModelsDirectoryResource()
  *
  * @param \Zend\Tool\Project\Profile $profile
  * @param string $moduleName
  * @return \Zend\Tool\Project\Profile\Resource
  */
 protected static function _getModelsDirectoryResource(ProjectProfile $profile, $moduleName = null)
 {
     $profileSearchParams = array();
     if ($moduleName != null && is_string($moduleName)) {
         $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
     }
     $profileSearchParams[] = 'modelsDirectory';
     return $profile->search($profileSearchParams);
 }
Exemplo n.º 3
0
 /**
  * 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)) {
         throw new 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;
 }
Exemplo n.º 4
0
 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 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;
     $currentChildResource = null;
     // 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;
 }
Exemplo n.º 5
0
 public static function hasResource(ProjectProfile $profile, $dbTableName, $moduleName = null)
 {
     $profileSearchParams = array();
     if ($moduleName != null && is_string($moduleName)) {
         $profileSearchParams = array('modulesDirectory', 'moduleDirectory' => array('moduleName' => $moduleName));
     }
     $profileSearchParams[] = 'modelsDirectory';
     $modelsDirectory = $profile->search($profileSearchParams);
     if (!$modelsDirectory instanceof ProjectProfile\Resource || !($dbTableDirectory = $modelsDirectory->search('DbTableDirectory'))) {
         return false;
     }
     $dbTableFile = $dbTableDirectory->search(array('DbTableFile' => array('dbTableName' => $dbTableName)));
     return $dbTableFile instanceof ProjectProfile\Resource ? true : false;
 }
Exemplo n.º 6
0
    /**
     * _unserializeRecurser()
     *
     * This method will be used to traverse the depths of the structure
     * as needed to *unserialize* the profile from an xmlIterator
     *
     * @param SimpleXMLIterator $xmlIterator
     * @param \Zend\Tool\Project\Profile\Resource\Resource $resource
     */
    protected function _unserializeRecurser(\SimpleXMLIterator $xmlIterator, Resource $resource = null)
    {

        foreach ($xmlIterator as $resourceName => $resourceData) {

            $contextName = $resourceName;
            $subResource = new Resource($contextName);
            $subResource->setProfile($this->_profile);

            if ($resourceAttributes = $resourceData->attributes()) {
                $attributes = array();
                foreach ($resourceAttributes as $attrName => $attrValue) {
                    $attributes[$attrName] = (string) $attrValue;
                }
                $subResource->setAttributes($attributes);
            }

            if ($resource) {
                $resource->append($subResource, false);
            } else {
                $this->_profile->append($subResource);
            }

            if ($this->_contextRepository->isOverwritableContext($contextName) == false) {
                $subResource->initializeContext();
            }

            if ($xmlIterator->hasChildren()) {
                self::_unserializeRecurser($xmlIterator->getChildren(), $subResource);
            }
        }
    }
Exemplo n.º 7
0
 /**
  * _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();
 }
Exemplo n.º 8
0
 public static function createResource(\Zend\Tool\Project\Profile $profile, $layoutName = 'layout')
 {
     $applicationDirectory = $profile->search('applicationDirectory');
     $layoutDirectory = $applicationDirectory->search('layoutsDirectory');
     if ($layoutDirectory == false) {
         $layoutDirectory = $applicationDirectory->createResource('layoutsDirectory');
     }
     $layoutScriptsDirectory = $layoutDirectory->search('layoutScriptsDirectory');
     if ($layoutScriptsDirectory == false) {
         $layoutScriptsDirectory = $layoutDirectory->createResource('layoutScriptsDirectory');
     }
     $layoutScriptFile = $layoutScriptsDirectory->search('layoutScriptFile', array('layoutName' => 'layout'));
     if ($layoutScriptFile == false) {
         $layoutScriptFile = $layoutScriptsDirectory->createResource('layoutScriptFile', array('layoutName' => 'layout'));
     }
     return $layoutScriptFile;
 }
Exemplo n.º 9
0
 /**
  * _getControllerFileResource()
  *
  * @param \Zend\Tool\Project\Profile $profile
  * @param string $controllerName
  * @param string $moduleName
  * @return \Zend\Tool\Project\Profile\Resource
  */
 protected static function _getControllerFileResource(ProjectProfile $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);
 }
Exemplo n.º 10
0
 public function testProfileThrowsExceptionOnLoadFromFileWithBadPathForProfileFile()
 {
     $this->setExpectedException('Zend\\Tool\\Project\\Exception');
     $profile = new Profile();
     $profile->setAttribute('projectProfileFile', '/path/should/not/exist');
     // missing file path or project path
     $profile->loadFromFile();
 }
Exemplo n.º 11
0
 /**
  * createLibraryResource()
  *
  * @param \Zend\Tool\Project\Profile $profile
  * @param string $libraryClassName
  * @return \Zend\Tool\Project\Profile\Resource
  */
 public static function createLibraryResource(ProjectProfile $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;
 }