AmfphpDiscovery.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * This file is part of amfPHP
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the license that is bundled
  8. * with this package in the file license.txt.
  9. */
  10. /**
  11. * includes
  12. * */
  13. require_once dirname(__FILE__) . '/AmfphpDiscoveryService.php';
  14. require_once dirname(__FILE__) . '/MethodDescriptor.php';
  15. require_once dirname(__FILE__) . '/ParameterDescriptor.php';
  16. require_once dirname(__FILE__) . '/ServiceDescriptor.php';
  17. /**
  18. * adds the discovery service, a service that returns information about available services.
  19. * Access is restricted by default(see restrictAccess below)
  20. *
  21. * @package Amfphp_Plugins_Discovery
  22. * @author Ariel Sommeria-Klein
  23. */
  24. class AmfphpDiscovery {
  25. /**
  26. * array of files and folders to ignore during introspection of the services dir
  27. * e.g. ignore dBug.php, an entire directory called 'classes' and also a subdirectory of one of the service directories (Vo/)
  28. * $this->pluginsConfig = array('AmfphpDiscovery' => array('excludePaths' => array('dBug', 'classes', 'Vo/')));
  29. * default is for ignoring Vo/ folder
  30. */
  31. protected $excludePaths = array('Vo/');
  32. /**
  33. * restrict access to amfphp_admin, the role set when using the back office. default is true.
  34. * @var boolean
  35. */
  36. protected $restrictAccess = true;
  37. /**
  38. * constructor.
  39. * adds filters to grab config about services and add discovery service. Low priority so that other plugins can add their services first
  40. * @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
  41. */
  42. public function __construct(array $config = null) {
  43. $filterManager = Amfphp_Core_FilterManager::getInstance();
  44. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERVICE_NAMES_2_CLASS_FIND_INFO, $this, 'filterServiceNames2ClassFindInfo', 99);
  45. $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_SERVICE_FOLDER_PATHS, $this, 'filterServiceFolderPaths', 99);
  46. if(isset($config['excludePaths'])){
  47. $this->excludePaths = $config['excludePaths'];
  48. }
  49. AmfphpDiscoveryService::$excludePaths = $this->excludePaths;
  50. if(isset($config['restrictAccess'])){
  51. $this->restrictAccess = $config['restrictAccess'];
  52. }
  53. AmfphpDiscoveryService::$restrictAccess = $this->restrictAccess;
  54. }
  55. /**
  56. * grabs serviceFolders from config
  57. * @param array serviceFolders array of absolute paths
  58. */
  59. public function filterServiceFolderPaths(array $serviceFolders){
  60. AmfphpDiscoveryService::$serviceFolders = $serviceFolders;
  61. return $serviceFolders;
  62. }
  63. /**
  64. * grabs serviceNames2ClassFindInfo from config and add discovery service
  65. * @param array $serviceNames2ClassFindInfo associative array of key -> class find info
  66. */
  67. public function filterServiceNames2ClassFindInfo(array $serviceNames2ClassFindInfo){
  68. $serviceNames2ClassFindInfo['AmfphpDiscoveryService'] = new Amfphp_Core_Common_ClassFindInfo( dirname(__FILE__) . '/AmfphpDiscoveryService.php', 'AmfphpDiscoveryService');
  69. AmfphpDiscoveryService::$serviceNames2ClassFindInfo = $serviceNames2ClassFindInfo;
  70. return $serviceNames2ClassFindInfo;
  71. }
  72. }
  73. ?>