Ejemplo n.º 1
0
 /**
  * createResource()
  *
  * Method to create a resource with a given context with specific attributes
  *
  * @param string $context
  * @param array $attributes
  * @return \Zend\Tool\Project\Profile\Resource
  */
 public function createResource($context, array $attributes = array())
 {
     if (is_string($context)) {
         $contextRegistry = \Zend\Tool\Project\Context\Repository::getInstance();
         if ($contextRegistry->hasContext($context)) {
             $context = $contextRegistry->getContext($context);
         } else {
             throw new Profile\Exception('Context by name ' . $context . ' was not found in the context registry.');
         }
     } elseif (!$context instanceof \Zend\Tool\Project\Context) {
         throw new Profile\Exception('Context must be of type string or Zend_Tool_Project_Context_Interface.');
     }
     $newResource = new Profile\Resource($context);
     if ($attributes) {
         $newResource->setAttributes($attributes);
     }
     /**
      * Interesting logic here:
      *
      * First set the parentResource (this will also be done inside append).  This will allow
      * the initialization routine to change the appendability of the parent resource.  This
      * is important to allow specific resources to be appendable by very specific sub-resources.
      */
     $newResource->setParentResource($this);
     $newResource->initializeContext();
     $this->append($newResource);
     return $newResource;
 }