|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Tool |
|
17 * @subpackage Framework |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: ProjectProviderFile.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Tool_Project_Context_Filesystem_File |
|
25 */ |
|
26 require_once 'Zend/Tool/Project/Context/Filesystem/File.php'; |
|
27 |
|
28 /** |
|
29 * @see Zend_CodeGenerator_Php_File |
|
30 */ |
|
31 require_once 'Zend/CodeGenerator/Php/File.php'; |
|
32 |
|
33 /** |
|
34 * This class is the front most class for utilizing Zend_Tool_Project |
|
35 * |
|
36 * A profile is a hierarchical set of resources that keep track of |
|
37 * items within a specific project. |
|
38 * |
|
39 * @category Zend |
|
40 * @package Zend_Tool |
|
41 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
42 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
43 */ |
|
44 class Zend_Tool_Project_Context_Zf_ProjectProviderFile extends Zend_Tool_Project_Context_Filesystem_File |
|
45 { |
|
46 |
|
47 /** |
|
48 * @var string |
|
49 */ |
|
50 protected $_projectProviderName = null; |
|
51 |
|
52 /** |
|
53 * @var array |
|
54 */ |
|
55 protected $_actionNames = array(); |
|
56 |
|
57 /** |
|
58 * init() |
|
59 * |
|
60 * @return Zend_Tool_Project_Context_Zf_ProjectProviderFile |
|
61 */ |
|
62 public function init() |
|
63 { |
|
64 |
|
65 $this->_projectProviderName = $this->_resource->getAttribute('projectProviderName'); |
|
66 $this->_actionNames = $this->_resource->getAttribute('actionNames'); |
|
67 $this->_filesystemName = ucfirst($this->_projectProviderName) . 'Provider.php'; |
|
68 |
|
69 if (strpos($this->_actionNames, ',')) { |
|
70 $this->_actionNames = explode(',', $this->_actionNames); |
|
71 } else { |
|
72 $this->_actionNames = ($this->_actionNames) ? array($this->_actionNames) : array(); |
|
73 } |
|
74 |
|
75 parent::init(); |
|
76 return $this; |
|
77 } |
|
78 |
|
79 /** |
|
80 * getPersistentAttributes() |
|
81 * |
|
82 * @return array |
|
83 */ |
|
84 public function getPersistentAttributes() |
|
85 { |
|
86 return array( |
|
87 'projectProviderName' => $this->getProjectProviderName(), |
|
88 'actionNames' => implode(',', $this->_actionNames) |
|
89 ); |
|
90 } |
|
91 |
|
92 /** |
|
93 * getName() |
|
94 * |
|
95 * @return string |
|
96 */ |
|
97 public function getName() |
|
98 { |
|
99 return 'ProjectProviderFile'; |
|
100 } |
|
101 |
|
102 /** |
|
103 * getProjectProviderName() |
|
104 * |
|
105 * @return string |
|
106 */ |
|
107 public function getProjectProviderName() |
|
108 { |
|
109 return $this->_projectProviderName; |
|
110 } |
|
111 |
|
112 /** |
|
113 * getContents() |
|
114 * |
|
115 * @return string |
|
116 */ |
|
117 public function getContents() |
|
118 { |
|
119 |
|
120 $filter = new Zend_Filter_Word_DashToCamelCase(); |
|
121 |
|
122 $className = $filter->filter($this->_projectProviderName) . 'Provider'; |
|
123 |
|
124 $class = new Zend_CodeGenerator_Php_Class(array( |
|
125 'name' => $className, |
|
126 'extendedClass' => 'Zend_Tool_Project_Provider_Abstract' |
|
127 )); |
|
128 |
|
129 $methods = array(); |
|
130 foreach ($this->_actionNames as $actionName) { |
|
131 $methods[] = new Zend_CodeGenerator_Php_Method(array( |
|
132 'name' => $actionName, |
|
133 'body' => ' /** @todo Implementation */' |
|
134 )); |
|
135 } |
|
136 |
|
137 if ($methods) { |
|
138 $class->setMethods($methods); |
|
139 } |
|
140 |
|
141 $codeGenFile = new Zend_CodeGenerator_Php_File(array( |
|
142 'requiredFiles' => array( |
|
143 'Zend/Tool/Project/Provider/Abstract.php', |
|
144 'Zend/Tool/Project/Provider/Exception.php' |
|
145 ), |
|
146 'classes' => array($class) |
|
147 )); |
|
148 |
|
149 return $codeGenFile->generate(); |
|
150 } |
|
151 |
|
152 } |