class Behavior
Hierarchy
- class \TYPO3\PharStreamWrapper\Behavior implements \TYPO3\PharStreamWrapper\Assertable
Expanded class hierarchy of Behavior
1 file declares its use of Behavior
- file.phar.inc in includes/
file.phar.inc
File
-
misc/
typo3/ phar-stream-wrapper/ src/ Behavior.php, line 14
Namespace
TYPO3\PharStreamWrapperView source
class Behavior implements Assertable {
const COMMAND_DIR_OPENDIR = 'dir_opendir';
const COMMAND_MKDIR = 'mkdir';
const COMMAND_RENAME = 'rename';
const COMMAND_RMDIR = 'rmdir';
const COMMAND_STEAM_METADATA = 'stream_metadata';
const COMMAND_STREAM_OPEN = 'stream_open';
const COMMAND_UNLINK = 'unlink';
const COMMAND_URL_STAT = 'url_stat';
/**
* @var string[]
*/
private $availableCommands = array(
self::COMMAND_DIR_OPENDIR,
self::COMMAND_MKDIR,
self::COMMAND_RENAME,
self::COMMAND_RMDIR,
self::COMMAND_STEAM_METADATA,
self::COMMAND_STREAM_OPEN,
self::COMMAND_UNLINK,
self::COMMAND_URL_STAT,
);
/**
* @var Assertable[]
*/
private $assertions;
/**
* @param Assertable $assertable
* @return static
*/
public function withAssertion(Assertable $assertable) {
$commands = func_get_args();
array_shift($commands);
$this->assertCommands($commands);
$commands = $commands ?: $this->availableCommands;
$target = clone $this;
foreach ($commands as $command) {
$target->assertions[$command] = $assertable;
}
return $target;
}
/**
* @param string $path
* @param string $command
* @return bool
*/
public function assert($path, $command) {
$this->assertCommand($command);
$this->assertAssertionCompleteness();
return $this->assertions[$command]
->assert($path, $command);
}
/**
* @param array $commands
*/
private function assertCommands(array $commands) {
$unknownCommands = array_diff($commands, $this->availableCommands);
if (empty($unknownCommands)) {
return;
}
throw new \LogicException(sprintf('Unknown commands: %s', implode(', ', $unknownCommands)), 1535189881);
}
private function assertCommand($command) {
if (in_array($command, $this->availableCommands, true)) {
return;
}
throw new \LogicException(sprintf('Unknown command "%s"', $command), 1535189882);
}
private function assertAssertionCompleteness() {
$undefinedAssertions = array_diff($this->availableCommands, array_keys($this->assertions));
if (empty($undefinedAssertions)) {
return;
}
throw new \LogicException(sprintf('Missing assertions for commands: %s', implode(', ', $undefinedAssertions)), 1535189883);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
Behavior::$assertions | private | property | ||
Behavior::$availableCommands | private | property | ||
Behavior::assert | public | function | Overrides Assertable::assert | |
Behavior::assertAssertionCompleteness | private | function | ||
Behavior::assertCommand | private | function | ||
Behavior::assertCommands | private | function | ||
Behavior::COMMAND_DIR_OPENDIR | constant | |||
Behavior::COMMAND_MKDIR | constant | |||
Behavior::COMMAND_RENAME | constant | |||
Behavior::COMMAND_RMDIR | constant | |||
Behavior::COMMAND_STEAM_METADATA | constant | |||
Behavior::COMMAND_STREAM_OPEN | constant | |||
Behavior::COMMAND_UNLINK | constant | |||
Behavior::COMMAND_URL_STAT | constant | |||
Behavior::withAssertion | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.