Example #1
0
 /**
  * Gets the static and dynamic dependencies for a class or group of classes.
  *
  * @param mixed $classes Either a string specifying a class, or a numerically indexed array
  *        of classes
  * @param array $options
  * @return array An array of the static and dynamic class dependencies
  * @todo Document valid options
  */
 public static function dependencies($classes, array $options = array())
 {
     $defaults = array('type' => null);
     $options += $defaults;
     $static = $dynamic = array();
     $trim = function ($c) {
         return trim(trim($c, '\\'));
     };
     $join = function ($i) {
         return join('', $i);
     };
     foreach ((array) $classes as $class) {
         $data = explode("\n", file_get_contents(\Radical\Core\Libraries::path($class)));
         $data = "<?php \n" . join("\n", preg_grep('/^\\s*use /', $data)) . "\n ?>";
         $classes = array_map($join, Parser::find($data, 'use *;', array('return' => 'content', 'lineBreaks' => true, 'startOfLine' => true, 'capture' => array('T_STRING', 'T_NS_SEPARATOR'))));
         if ($classes) {
             $static = array_unique(array_merge($static, array_map($trim, $classes)));
         }
         $classes = static::info($class . '::$_classes', array('value'));
         if (isset($classes['value'])) {
             $dynamic = array_merge($dynamic, array_map($trim, array_values($classes['value'])));
         }
     }
     if (empty($options['type'])) {
         return array_unique(array_merge($static, $dynamic));
     }
     $type = $options['type'];
     return isset(${$type}) ? ${$type} : null;
 }