PageRenderTime 46ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/web/vendors/PHP/Depend/Visitor/AbstractVisitor.php

https://bitbucket.org/bestteam/expenses
PHP | 520 lines | 203 code | 46 blank | 271 comment | 1 complexity | 8bab1e3904aa26afab73f6d7c2661033 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * This file is part of PHP_Depend.
  4. *
  5. * PHP Version 5
  6. *
  7. * Copyright (c) 2008-2012, Manuel Pichler <mapi@pdepend.org>.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * * Neither the name of Manuel Pichler nor the names of his
  23. * contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * @category QualityAssurance
  40. * @package PHP_Depend
  41. * @subpackage Visitor
  42. * @author Manuel Pichler <mapi@pdepend.org>
  43. * @copyright 2008-2012 Manuel Pichler. All rights reserved.
  44. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  45. * @version SVN: $Id$
  46. * @link http://pdepend.org/
  47. */
  48. /**
  49. * This abstract visitor implementation provides a default traversal algorithm
  50. * that can be used for custom visitors.
  51. *
  52. * @category QualityAssurance
  53. * @package PHP_Depend
  54. * @subpackage Visitor
  55. * @author Manuel Pichler <mapi@pdepend.org>
  56. * @copyright 2008-2012 Manuel Pichler. All rights reserved.
  57. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  58. * @version Release: 1.1.0
  59. * @link http://pdepend.org/
  60. */
  61. abstract class PHP_Depend_Visitor_AbstractVisitor
  62. implements PHP_Depend_VisitorI
  63. {
  64. /**
  65. * List of all registered listeners.
  66. *
  67. * @var array(PHP_Depend_Visitor_ListenerI) $_listeners
  68. */
  69. private $listeners = array();
  70. /**
  71. * Returns an iterator with all registered visit listeners.
  72. *
  73. * @return Iterator
  74. */
  75. public function getVisitListeners()
  76. {
  77. return new ArrayIterator($this->listeners);
  78. }
  79. /**
  80. * Adds a new listener to this node visitor.
  81. *
  82. * @param PHP_Depend_Visitor_ListenerI $listener The new visit listener.
  83. *
  84. * @return void
  85. */
  86. public function addVisitListener(PHP_Depend_Visitor_ListenerI $listener)
  87. {
  88. if (in_array($listener, $this->listeners, true) === false) {
  89. $this->listeners[] = $listener;
  90. }
  91. }
  92. /**
  93. * Visits a class node.
  94. *
  95. * @param PHP_Depend_Code_Class $class The current class node.
  96. *
  97. * @return void
  98. * @see PHP_Depend_VisitorI::visitClass()
  99. */
  100. public function visitClass(PHP_Depend_Code_Class $class)
  101. {
  102. $this->fireStartClass($class);
  103. $class->getSourceFile()->accept($this);
  104. foreach ($class->getProperties() as $property) {
  105. $property->accept($this);
  106. }
  107. foreach ($class->getMethods() as $method) {
  108. $method->accept($this);
  109. }
  110. $this->fireEndClass($class);
  111. }
  112. /**
  113. * Visits a trait node.
  114. *
  115. * @param PHP_Depend_Code_Trait $trait The current trait node.
  116. *
  117. * @return void
  118. * @since 1.0.0
  119. */
  120. public function visitTrait(PHP_Depend_Code_Trait $trait)
  121. {
  122. $this->fireStartTrait($trait);
  123. $trait->getSourceFile()->accept($this);
  124. foreach ($trait->getMethods() as $method) {
  125. $method->accept($this);
  126. }
  127. $this->fireEndTrait($trait);
  128. }
  129. /**
  130. * Visits a file node.
  131. *
  132. * @param PHP_Depend_Code_File $file The current file node.
  133. *
  134. * @return void
  135. * @see PHP_Depend_VisitorI::visitFile()
  136. */
  137. public function visitFile(PHP_Depend_Code_File $file)
  138. {
  139. $this->fireStartFile($file);
  140. $this->fireEndFile($file);
  141. }
  142. /**
  143. * Visits a function node.
  144. *
  145. * @param PHP_Depend_Code_Function $function The current function node.
  146. *
  147. * @return void
  148. * @see PHP_Depend_VisitorI::visitFunction()
  149. */
  150. public function visitFunction(PHP_Depend_Code_Function $function)
  151. {
  152. $this->fireStartFunction($function);
  153. $function->getSourceFile()->accept($this);
  154. foreach ($function->getParameters() as $parameter) {
  155. $parameter->accept($this);
  156. }
  157. $this->fireEndFunction($function);
  158. }
  159. /**
  160. * Visits a code interface object.
  161. *
  162. * @param PHP_Depend_Code_Interface $interface The context code interface.
  163. *
  164. * @return void
  165. * @see PHP_Depend_VisitorI::visitInterface()
  166. */
  167. public function visitInterface(PHP_Depend_Code_Interface $interface)
  168. {
  169. $this->fireStartInterface($interface);
  170. $interface->getSourceFile()->accept($this);
  171. foreach ($interface->getMethods() as $method) {
  172. $method->accept($this);
  173. }
  174. $this->fireEndInterface($interface);
  175. }
  176. /**
  177. * Visits a method node.
  178. *
  179. * @param PHP_Depend_Code_Class $method The method class node.
  180. *
  181. * @return void
  182. * @see PHP_Depend_VisitorI::visitMethod()
  183. */
  184. public function visitMethod(PHP_Depend_Code_Method $method)
  185. {
  186. $this->fireStartMethod($method);
  187. foreach ($method->getParameters() as $parameter) {
  188. $parameter->accept($this);
  189. }
  190. $this->fireEndMethod($method);
  191. }
  192. /**
  193. * Visits a package node.
  194. *
  195. * @param PHP_Depend_Code_Class $package The package class node.
  196. * @return void
  197. */
  198. public function visitPackage(PHP_Depend_Code_Package $package)
  199. {
  200. $this->fireStartPackage($package);
  201. foreach ($package->getClasses() as $class) {
  202. $class->accept($this);
  203. }
  204. foreach ($package->getInterfaces() as $interface) {
  205. $interface->accept($this);
  206. }
  207. foreach ($package->getTraits() as $trait) {
  208. $trait->accept($this);
  209. }
  210. foreach ($package->getFunctions() as $function) {
  211. $function->accept($this);
  212. }
  213. $this->fireEndPackage($package);
  214. }
  215. /**
  216. * Visits a parameter node.
  217. *
  218. * @param PHP_Depend_Code_Parameter $parameter The parameter node.
  219. *
  220. * @return void
  221. */
  222. public function visitParameter(PHP_Depend_Code_Parameter $parameter)
  223. {
  224. $this->fireStartParameter($parameter);
  225. $this->fireEndParameter($parameter);
  226. }
  227. /**
  228. * Visits a property node.
  229. *
  230. * @param PHP_Depend_Code_Property $property The property class node.
  231. *
  232. * @return void
  233. * @see PHP_Depend_VisitorI::visitProperty()
  234. */
  235. public function visitProperty(PHP_Depend_Code_Property $property)
  236. {
  237. $this->fireStartProperty($property);
  238. $this->fireEndProperty($property);
  239. }
  240. /**
  241. * Sends a start class event.
  242. *
  243. * @param PHP_Depend_Code_Class $class The context class instance.
  244. *
  245. * @return void
  246. */
  247. protected function fireStartClass(PHP_Depend_Code_Class $class)
  248. {
  249. foreach ($this->listeners as $listener) {
  250. $listener->startVisitClass($class);
  251. }
  252. }
  253. /**
  254. * Sends an end class event.
  255. *
  256. * @param PHP_Depend_Code_Class $class The context class instance.
  257. *
  258. * @return void
  259. */
  260. protected function fireEndClass(PHP_Depend_Code_Class $class)
  261. {
  262. foreach ($this->listeners as $listener) {
  263. $listener->endVisitClass($class);
  264. }
  265. }
  266. /**
  267. * Sends a start trait event.
  268. *
  269. * @param PHP_Depend_Code_Trait $trait The context trait instance.
  270. *
  271. * @return void
  272. */
  273. protected function fireStartTrait(PHP_Depend_Code_Trait $trait)
  274. {
  275. foreach ($this->listeners as $listener) {
  276. $listener->startVisitTrait($trait);
  277. }
  278. }
  279. /**
  280. * Sends an end trait event.
  281. *
  282. * @param PHP_Depend_Code_Trait $trait The context trait instance.
  283. *
  284. * @return void
  285. */
  286. protected function fireEndTrait(PHP_Depend_Code_Trait $trait)
  287. {
  288. foreach ($this->listeners as $listener) {
  289. $listener->endVisitTrait($trait);
  290. }
  291. }
  292. /**
  293. * Sends a start file event.
  294. *
  295. * @param PHP_Depend_Code_File $file The context file.
  296. *
  297. * @return void
  298. */
  299. protected function fireStartFile(PHP_Depend_Code_File $file)
  300. {
  301. foreach ($this->listeners as $listener) {
  302. $listener->startVisitFile($file);
  303. }
  304. }
  305. /**
  306. * Sends an end file event.
  307. *
  308. * @param PHP_Depend_Code_File $file The context file instance.
  309. *
  310. * @return void
  311. */
  312. protected function fireEndFile(PHP_Depend_Code_File $file)
  313. {
  314. foreach ($this->listeners as $listener) {
  315. $listener->endVisitFile($file);
  316. }
  317. }
  318. /**
  319. * Sends a start function event.
  320. *
  321. * @param PHP_Depend_Code_Function $function The context function instance.
  322. *
  323. * @return void
  324. */
  325. protected function fireStartFunction(PHP_Depend_Code_Function $function)
  326. {
  327. foreach ($this->listeners as $listener) {
  328. $listener->startVisitFunction($function);
  329. }
  330. }
  331. /**
  332. * Sends an end function event.
  333. *
  334. * @param PHP_Depend_Code_Function $function The context function instance.
  335. *
  336. * @return void
  337. */
  338. protected function fireEndFunction(PHP_Depend_Code_Function $function)
  339. {
  340. foreach ($this->listeners as $listener) {
  341. $listener->endVisitFunction($function);
  342. }
  343. }
  344. /**
  345. * Sends a start interface event.
  346. *
  347. * @param PHP_Depend_Code_Interface $interface The context interface instance.
  348. *
  349. * @return void
  350. */
  351. protected function fireStartInterface(PHP_Depend_Code_Interface $interface)
  352. {
  353. foreach ($this->listeners as $listener) {
  354. $listener->startVisitInterface($interface);
  355. }
  356. }
  357. /**
  358. * Sends an end interface event.
  359. *
  360. * @param PHP_Depend_Code_Interface $interface The context interface instance.
  361. *
  362. * @return void
  363. */
  364. protected function fireEndInterface(PHP_Depend_Code_Interface $interface)
  365. {
  366. foreach ($this->listeners as $listener) {
  367. $listener->endVisitInterface($interface);
  368. }
  369. }
  370. /**
  371. * Sends a start method event.
  372. *
  373. * @param PHP_Depend_Code_Method $method The context method instance.
  374. *
  375. * @return void
  376. */
  377. protected function fireStartMethod(PHP_Depend_Code_Method $method)
  378. {
  379. foreach ($this->listeners as $listener) {
  380. $listener->startVisitMethod($method);
  381. }
  382. }
  383. /**
  384. * Sends an end method event.
  385. *
  386. * @param PHP_Depend_Code_Method $method The context method instance.
  387. *
  388. * @return void
  389. */
  390. protected function fireEndMethod(PHP_Depend_Code_Method $method)
  391. {
  392. foreach ($this->listeners as $listener) {
  393. $listener->endVisitMethod($method);
  394. }
  395. }
  396. /**
  397. * Sends a start package event.
  398. *
  399. * @param PHP_Depend_Code_Package $package The context package instance.
  400. *
  401. * @return void
  402. */
  403. protected function fireStartPackage(PHP_Depend_Code_Package $package)
  404. {
  405. foreach ($this->listeners as $listener) {
  406. $listener->startVisitPackage($package);
  407. }
  408. }
  409. /**
  410. * Sends an end package event.
  411. *
  412. * @param PHP_Depend_Code_Package $package The context package instance.
  413. *
  414. * @return void
  415. */
  416. protected function fireEndPackage(PHP_Depend_Code_Package $package)
  417. {
  418. foreach ($this->listeners as $listener) {
  419. $listener->endVisitPackage($package);
  420. }
  421. }
  422. /**
  423. * Sends a start parameter event.
  424. *
  425. * @param PHP_Depend_Code_Parameter $parameter The context parameter instance.
  426. *
  427. * @return void
  428. */
  429. protected function fireStartParameter(PHP_Depend_Code_Parameter $parameter)
  430. {
  431. foreach ($this->listeners as $listener) {
  432. $listener->startVisitParameter($parameter);
  433. }
  434. }
  435. /**
  436. * Sends a end parameter event.
  437. *
  438. * @param PHP_Depend_Code_Parameter $parameter The context parameter instance.
  439. *
  440. * @return void
  441. */
  442. protected function fireEndParameter(PHP_Depend_Code_Parameter $parameter)
  443. {
  444. foreach ($this->listeners as $listener) {
  445. $listener->endVisitParameter($parameter);
  446. }
  447. }
  448. /**
  449. * Sends a start property event.
  450. *
  451. * @param PHP_Depend_Code_Property $property The context property instance.
  452. *
  453. * @return void
  454. */
  455. protected function fireStartProperty(PHP_Depend_Code_Property $property)
  456. {
  457. foreach ($this->listeners as $listener) {
  458. $listener->startVisitProperty($property);
  459. }
  460. }
  461. /**
  462. * Sends an end property event.
  463. *
  464. * @param PHP_Depend_Code_Property $property The context property instance.
  465. *
  466. * @return void
  467. */
  468. protected function fireEndProperty(PHP_Depend_Code_Property $property)
  469. {
  470. foreach ($this->listeners as $listener) {
  471. $listener->endVisitProperty($property);
  472. }
  473. }
  474. }