trait InvokeMethodTrait in Search API Solr 8.3
Same name and namespace in other branches
- 8 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait
- 8.2 tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait
- 4.x tests/src/Traits/InvokeMethodTrait.php \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait
Provides a function to invoke protected/private methods of a class.
Hierarchy
- trait \Drupal\Tests\search_api_solr\Traits\InvokeMethodTrait
3 files declare their use of InvokeMethodTrait
- SearchApiBackendUnitTest.php in tests/
src/ Unit/ SearchApiBackendUnitTest.php - SearchApiSolrTest.php in tests/
src/ Kernel/ SearchApiSolrTest.php - SolrFieldNamesTest.php in tests/
src/ Kernel/ SolrFieldNamesTest.php
File
- tests/
src/ Traits/ InvokeMethodTrait.php, line 8
Namespace
Drupal\Tests\search_api_solr\TraitsView source
trait InvokeMethodTrait {
/**
* Calls protected/private method of a class.
*
* @param object &$object
* Instantiated object that we will run method on.
* @param string $methodName
* Method name to call.
* @param array $parameters
* Array of parameters to pass into method.
* @param array $protectedProperties
* Array of values that should be set on protected properties.
*
* @return mixed
* Method return.
*/
protected function invokeMethod(&$object, $methodName, array $parameters = [], array $protectedProperties = []) {
$reflection = new \ReflectionClass(get_class($object));
foreach ($protectedProperties as $property => $value) {
$property = $reflection
->getProperty($property);
$property
->setAccessible(TRUE);
$property
->setValue($object, $value);
}
$method = $reflection
->getMethod($methodName);
$method
->setAccessible(TRUE);
return $method
->invokeArgs($object, $parameters);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InvokeMethodTrait:: |
protected | function | Calls protected/private method of a class. |