File indexing completed on 2024-06-23 05:55:51

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Tool
0017  * @subpackage Framework
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Tool_Project_Context_Filesystem_File
0025  */
0026 // require_once 'Zend/Tool/Project/Context/Filesystem/File.php';
0027 
0028 /**
0029  * @see Zend_CodeGenerator_Php_File
0030  */
0031 // require_once 'Zend/CodeGenerator/Php/File.php';
0032 
0033 /**
0034  * This class is the front most class for utilizing Zend_Tool_Project
0035  *
0036  * A profile is a hierarchical set of resources that keep track of
0037  * items within a specific project.
0038  *
0039  * @category   Zend
0040  * @package    Zend_Tool
0041  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0042  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0043  */
0044 class Zend_Tool_Project_Context_Zf_ProjectProviderFile extends Zend_Tool_Project_Context_Filesystem_File
0045 {
0046 
0047     /**
0048      * @var string
0049      */
0050     protected $_projectProviderName = null;
0051 
0052     /**
0053      * @var array
0054      */
0055     protected $_actionNames = array();
0056 
0057     /**
0058      * init()
0059      *
0060      * @return Zend_Tool_Project_Context_Zf_ProjectProviderFile
0061      */
0062     public function init()
0063     {
0064 
0065         $this->_projectProviderName = $this->_resource->getAttribute('projectProviderName');
0066         $this->_actionNames = $this->_resource->getAttribute('actionNames');
0067         $this->_filesystemName = ucfirst($this->_projectProviderName) . 'Provider.php';
0068 
0069         if (strpos($this->_actionNames, ',')) {
0070             $this->_actionNames = explode(',', $this->_actionNames);
0071         } else {
0072             $this->_actionNames = ($this->_actionNames) ? array($this->_actionNames) : array();
0073         }
0074 
0075         parent::init();
0076         return $this;
0077     }
0078 
0079     /**
0080      * getPersistentAttributes()
0081      *
0082      * @return array
0083      */
0084     public function getPersistentAttributes()
0085     {
0086         return array(
0087             'projectProviderName' => $this->getProjectProviderName(),
0088             'actionNames' => implode(',', $this->_actionNames)
0089             );
0090     }
0091 
0092     /**
0093      * getName()
0094      *
0095      * @return string
0096      */
0097     public function getName()
0098     {
0099         return 'ProjectProviderFile';
0100     }
0101 
0102     /**
0103      * getProjectProviderName()
0104      *
0105      * @return string
0106      */
0107     public function getProjectProviderName()
0108     {
0109         return $this->_projectProviderName;
0110     }
0111 
0112     /**
0113      * getContents()
0114      *
0115      * @return string
0116      */
0117     public function getContents()
0118     {
0119 
0120         $filter = new Zend_Filter_Word_DashToCamelCase();
0121 
0122         $className = $filter->filter($this->_projectProviderName) . 'Provider';
0123 
0124         $class = new Zend_CodeGenerator_Php_Class(array(
0125             'name' => $className,
0126             'extendedClass' => 'Zend_Tool_Project_Provider_Abstract'
0127             ));
0128 
0129         $methods = array();
0130         foreach ($this->_actionNames as $actionName) {
0131             $methods[] = new Zend_CodeGenerator_Php_Method(array(
0132                 'name' => $actionName,
0133                 'body' => '        /** @todo Implementation */'
0134                 ));
0135         }
0136 
0137         if ($methods) {
0138             $class->setMethods($methods);
0139         }
0140 
0141         $codeGenFile = new Zend_CodeGenerator_Php_File(array(
0142             'requiredFiles' => array(
0143                 'Zend/Tool/Project/Provider/Abstract.php',
0144                 'Zend/Tool/Project/Provider/Exception.php'
0145                 ),
0146             'classes' => array($class)
0147             ));
0148 
0149         return $codeGenFile->generate();
0150     }
0151 
0152 }