public function process($object) { $methods = $this->reflector->reflect($object)->getMethods(ReflectionMethod::IS_PUBLIC); // Get the actual name of the method $methods = array_map(function ($reflection) { return $reflection->getName(); }, $methods); // Filter out all but the getters $methods = array_filter($methods, function ($method) { return preg_match("/^get[A-Z]/u", $method); }); // Make sure to reindex the results after the filters return array_values($methods); }
/** * Pull the public methods out of a class * * Optionally, don't get the inherited methods (default), and mask out the magic methods (default) * * @param string $fqcn * * @return array */ private function extractPublicMethods($fqcn) { $class = $this->reflector->reflect($fqcn); $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC); $class = $class->getShortName(); // Filter out inherited methods && magic methods $methods = array_filter($methods, function ($method) use($fqcn) { return $method->class === $fqcn && substr($method->name, 0, 2) != '__'; }); $signature_methods = []; foreach ($methods as $method) { $signature_methods[lcfirst($class) . ucfirst($method->name)] = ['class' => $class, 'method' => $method->name, 'doc' => $this->decipher->process($method->getDocComment())]; } return $signature_methods; }
/** * @test */ public function it_returns_the_expected_results() { $this->assertInstanceOf('ReflectionClass', $this->reflector->reflect('stdClass')); $class = new stdClass(); $this->assertInstanceOf('ReflectionClass', $this->reflector->reflect($class)); }
/** * Reflect on the class from it's contents * * @param array $contents * * @return ReflectionClass * @throws InvalidArgumentException * */ private function reflectClass(array $contents) { return $this->reflector->reflect($this->class_name_getter->process($contents)); }