public static function factory($class, $method = null)
    {
        if (is_object($class))
            $class = get_class($class);
        $class = (string)$class;
        if (!isset(self::$methods[$class])) {
            $classReflection = new \ReflectionClass($class);
            $methods = $classReflection->getMethods();
            self::$methods[$class] = array();
            foreach ($methods as $methodReflection) {
                if ($methodReflection->class != $class) {
                    self::$methods[$class][$methodReflection->name] = self::factory($methodReflection->class, $methodReflection->name);
                } else {
                    self::$methods[$class][$methodReflection->name] = new self($class, $methodReflection->name);
                    self::$methods[$class][$methodReflection->name]->setAccessible(true);
                }
            }
        }
        if (isset($method)) {
            if (!isset(self::$methods[$class][$method])) {
                self::$methods[$class][$method] = new self($class, $method);
                self::$methods[$class][$method]->setAccessible(true);
            }
            return self::$methods[$class][$method];
        } else
            return array_values(self::$methods[$class]);
    }