This is simply a helper method that calls ReflectionObject::createFromInstance().
public static createFromInstance ( object $instance ) : |
||
$instance | object | |
return |
/** * createFromPlaceholder extracts the methods of a placeholder that can be called from a template. * * Methods must be public and take a Call object as the first argument. * * @return \nochso\WriteMe\Reflection\Method[] */ public function createFromPlaceholder(Placeholder $placeholder) { $methods = []; $class = Reflection\ReflectionClass::createFromInstance($placeholder); foreach ($class->getMethods() as $method) { if ($this->isCallable($method)) { $methods[] = new Method($placeholder, $method); } } return $methods; }
public function writemePlaceholderDocs(Call $call) { $classes = []; foreach ($this->placeholders->toArray() as $placeholder) { $classes[get_class($placeholder)] = ReflectionClass::createFromInstance($placeholder); } $template = new TemplateData(); $template->setHeaderStartLevel($this->options->getValue('placeholder-docs.header-depth')); $template->prepare($classes, $this->placeholders); $docs = $template->render('full.php'); $docs = (new Converter())->escape($docs); $call->replace($docs); }
/** * Create a reflection of an instance's property by it's name * * @param object $instance * @param string $propertyName * @return ReflectionMethod */ public static function createFromInstance($instance, $propertyName) { return ReflectionClass::createFromInstance($instance)->getProperty($propertyName); }
/** * Create a reflection of a parameter using an instance * * @param object $instance * @param string $methodName * @param string $parameterName * @return ReflectionParameter */ public static function createFromClassInstanceAndMethod($instance, $methodName, $parameterName) { return ReflectionClass::createFromInstance($instance)->getMethod($methodName)->getParameter($parameterName); }
public function testCreateFromInstanceThrowsExceptionWhenInvalidArgumentProvided() { $this->setExpectedException(\InvalidArgumentException::class, 'Instance must be an instance of an object'); ReflectionClass::createFromInstance('invalid argument'); }
/** * Create a reflection of a method by it's name using an instance * * @param object $instance * @param string $methodName * @return ReflectionMethod */ public static function createFromInstance($instance, $methodName) { return ReflectionClass::createFromInstance($instance)->getMethod($methodName); }