class CollectFilesInjectedApi in X Autoload 7.5
Same name and namespace in other branches
- 7.4 lib/ClassFinder/InjectedApi/CollectFilesInjectedApi.php \Drupal\xautoload\ClassFinder\InjectedApi\CollectFilesInjectedApi
To help testability, we use an injected API instead of just a return value. The injected API can be mocked to provide a mocked file_exists(), and to monitor all suggested candidates, not just the correct return value.
Hierarchy
- class \Drupal\xautoload\ClassFinder\InjectedApi\AbstractInjectedApi implements InjectedApiInterface
- class \Drupal\xautoload\ClassFinder\InjectedApi\CollectFilesInjectedApi
Expanded class hierarchy of CollectFilesInjectedApi
1 file declares its use of CollectFilesInjectedApi
- XAutoloadUnitTestCase.php in lib/
Drupal/ xautoload/ Tests/ XAutoloadUnitTestCase.php
File
- src/
ClassFinder/ InjectedApi/ CollectFilesInjectedApi.php, line 10
Namespace
Drupal\xautoload\ClassFinder\InjectedApiView source
class CollectFilesInjectedApi extends AbstractInjectedApi {
/**
* @var string
* The method that, if called with $this->file, will return TRUE.
*/
protected $methodName;
/**
* @var string
* The file where $this->$method($this->file) will return TRUE.
*/
protected $file;
/**
* @var array[]
* All files that were suggested.
*/
protected $suggestions;
/**
* @param string $class_name
* @var string $method
* The method that, if called with $this->file, will return TRUE.
* @param string $file
* The file where $this->$method($this->file) will return TRUE.
*/
function __construct($class_name, $method_name, $file) {
$this->methodName = $method_name;
$this->file = $file;
parent::__construct($class_name);
}
/**
* When the process has finished, use this to return the result.
*
* @return string
* The file that is supposed to declare the class.
*/
function getSuggestions() {
return $this->suggestions;
}
/**
* Suggest a file that, if the file exists,
* has to declare the class we are looking for.
* Only keep the class on success.
*
* @param string $file
* The file that is supposed to declare the class.
*
* @return bool
* TRUE, if the file exists.
* FALSE, otherwise.
*/
function suggestFile($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return __FUNCTION__ === $this->methodName && $file === $this->file;
}
/**
* Same as suggestFile(), but skip the file_exists(),
* assuming that we already know the file exists.
*
* This could make sense if a plugin already did the file_exists() check.
*
* @param string $file
* The file that is supposed to declare the class.
*
* @return bool
* TRUE, if the file was found - which is always.
*/
function suggestFile_skipFileExists($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return TRUE;
}
/**
* Same as suggestFile(), but assume that file_exists() returns TRUE.
*
* @param string $file
* The file that is supposed to declare the class.
*
* @return bool
* TRUE, if the file was found - which is always.
*/
function suggestFile_checkNothing($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return TRUE;
}
/**
* Same as suggestFile(), but check the full PHP include path.
*
* @param string $file
* The file that is supposed to declare the class.
*
* @return bool
* TRUE, if the file exists.
* FALSE, otherwise.
*/
function suggestFile_checkIncludePath($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return __FUNCTION__ == $this->methodName && $file === $this->file;
}
/**
* {@inheritdoc}
*/
function guessFile($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return __FUNCTION__ == $this->methodName && $file === $this->file;
}
/**
* {@inheritdoc}
*/
function guessPath($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return __FUNCTION__ == $this->methodName && $file === $this->file;
}
/**
* {@inheritdoc}
*/
function claimFile($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return TRUE;
}
/**
* {@inheritdoc}
*/
function claimPath($file) {
$this->suggestions[] = array(
__FUNCTION__,
$file,
);
return __FUNCTION__ == $this->methodName && $file === $this->file;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractInjectedApi:: |
protected | property | The class name to look for. Set in the constructor. | |
AbstractInjectedApi:: |
static | function | Dummy method to force autoloading this class (or an ancestor). | |
AbstractInjectedApi:: |
function |
Get the name of the class we are looking for. Overrides InjectedApiInterface:: |
||
AbstractInjectedApi:: |
function |
This is done in the injected api object, so we can easily provide a mock
implementation. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
protected | property | The file where $this->$method($this->file) will return TRUE. | |
CollectFilesInjectedApi:: |
protected | property | The method that, if called with $this->file, will return TRUE. | |
CollectFilesInjectedApi:: |
protected | property | All files that were suggested. | |
CollectFilesInjectedApi:: |
function |
Suggest a file that MUST exist, and if so, MUST declare the class we are
looking for. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
Suggest a file that MAY exist, and if so, MUST declare the class we are
looking for. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function | When the process has finished, use this to return the result. | ||
CollectFilesInjectedApi:: |
function |
Suggest a file that MUST exists, and that MAY declare the class we are
looking for. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
Suggest a file that MAY exist, and that MAY declare the class we are
looking for. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
Suggest a file that, if the file exists,
has to declare the class we are looking for.
Only keep the class on success. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
Same as suggestFile(), but check the full PHP include path. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
Same as suggestFile(), but assume that file_exists() returns TRUE. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
Same as suggestFile(), but skip the file_exists(),
assuming that we already know the file exists. Overrides InjectedApiInterface:: |
||
CollectFilesInjectedApi:: |
function |
The method that, if called with $this->file, will return TRUE. Overrides AbstractInjectedApi:: |