Source for file DiscoveryService.php

Documentation is available at DiscoveryService.php

  1. <?php
  2. include_once(AMFPHP_BASE . "shared/util/MethodTable.php");
  3. /**
  4.  * A built-in amfphp service that allows introspection into services and their methods.
  5.  * Remove from production servers
  6.  */
  7. {
  8.     /**
  9.      * Get the list of services
  10.      * @returns An array of array ready to be bound to a Tree
  11.      */
  12.     function getServices()
  13.     {
  14.         $this->_omit = array();
  15.         $this->_path dirname(dirname(realpath(__FILE__))) '/';
  16.         $services $this->_listServices();
  17.         //Now sort on key
  18.         ksort($services);
  19.         $out = array();
  20.         foreach($services as $key => $val)
  21.         {
  22.             if($key == "zzz_default")
  23.             {
  24.                 foreach($val as $key2 => $val2)
  25.                 {
  26.                     $out[= array("label" => $val2[0]"data" => $val2[1]);
  27.                 }
  28.             }
  29.             else
  30.             {
  31.                 $children = array();
  32.                 foreach($val as $key2 => $val2)
  33.                 {
  34.                     $children[= array("label" => $val2[0]"data" => $val2[1]);
  35.                 }
  36.                 $out[= array("label" => $key"children" => $children"open" => true);
  37.             }
  38.         }
  39.         return $out;
  40.     }
  41.     
  42.     /**
  43.      * Describe a service and all its methods
  44.      * @param $data An object containing 'label' and 'data' keys
  45.      */
  46.     function describeService($data)
  47.     {
  48.         $className $data['label'];
  49.         //Sanitize path
  50.         $path str_replace('..'''$data['data']);
  51.         //Generate the method table from this info
  52.         $this->_path dirname(dirname(realpath(__FILE__))) . DIRECTORY_SEPARATOR;
  53.         
  54.         $methodTable = MethodTable::create($this->_path $path $className '.php'NULL$classComment);
  55.         return array($methodTable$classComment);
  56.     }
  57.     
  58.     function _listServices($dir ""$suffix "")
  59.     {
  60.         if($dir == "")
  61.         {
  62.             $dir $this->_path;
  63.         }
  64.         $services = array();
  65.         if(in_array($suffix$this->_omit))return}
  66.         if ($handle opendir($dir $suffix))
  67.         {
  68.             while (false !== ($file readdir($handle))) 
  69.             {
  70.                 chdir(dirname(__FILE__));
  71.                 if ($file != "." && $file != ".."
  72.                 {
  73.                     if(is_file($dir $suffix $file))
  74.                     {
  75.                         if(strpos($file'.methodTable'!== FALSE)
  76.                         {
  77.                             continue;
  78.                         }
  79.                         $index strrpos($file'.');
  80.                         $before substr($file0$index);
  81.                         $after substr($file$index + 1);
  82.                         
  83.                         if($after == 'php')
  84.                         {
  85.                             $loc "zzz_default";
  86.                             if($suffix != "")
  87.                             {
  88.                                 $loc str_replace(DIRECTORY_SEPARATOR,'.'substr($suffix0-1));
  89.                             }
  90.                             
  91.                             if($services[$loc== NULL)
  92.                             {
  93.                                 $services[$loc= array();
  94.                             }
  95.                             $services[$loc][= array($before$suffix);
  96.                             //array_push($this->_classes, $before);
  97.                         }
  98.                         
  99.                     }
  100.                     elseif(is_dir($dir $suffix $file))
  101.                     {
  102.                         $insideDir $this->_listServices($dir$suffix $file . DIRECTORY_SEPARATOR);
  103.                         if(is_array($insideDir))
  104.                         {
  105.                             $services $services $insideDir;
  106.                         }
  107.                     }
  108.                 }
  109.             }
  110.         }else{
  111.             //echo("error");
  112.         }
  113.         closedir($handle);
  114.         return $services;
  115.     }
  116.     
  117.     function listTemplates()
  118.     {
  119.         $templates = array();
  120.         if ($handle opendir('templates'))
  121.         {
  122.             while (false !== ($file readdir($handle))) 
  123.             {
  124.                 //chdir(dirname(__FILE__));
  125.                 if ($file != "." && $file != ".."
  126.                 {
  127.                     if(is_file('./templates/' $file))
  128.                     {
  129.                         $index strrpos($file'.');
  130.                         $before substr($file0$index);
  131.                         $after substr($file$index + 1);
  132.                         
  133.                         if($after == 'php')
  134.                         {
  135.                             $templates[$before;
  136.                         }
  137.                     }
  138.                 }
  139.             }
  140.         }
  141.         else
  142.         {
  143.             trigger_error("Could not open templates dir");
  144.         }
  145.         return $templates;
  146.     }
  147. }

Documentation generated on Fri, 06 Jul 2007 19:54:48 +0100 by phpDocumentor 1.3.1