15 private $canonical_name =
null;
25 if ($this->canonical_name ===
null) {
28 return $this->canonical_name;
38 $cls = explode(
"\\", get_class($this));
40 $cur = array_pop($cls);
41 while ($cur !==
"Component" && count($cls) > 0) {
42 $name[] = preg_replace(
"%([a-z])([A-Z])%",
"$1 $2", $cur);
43 $cur = array_pop($cls);
45 return implode(
" ",
$name);
61 assert(is_string($which));
62 assert(is_bool($check));
65 throw new \InvalidArgumentException(
"Argument '$which': $message");
134 if (!is_object($value)) {
135 $message =
"expected $name, got '$value'";
137 $message =
"expected $name, got object.";
157 foreach ($values as
$key => $value) {
166 if ($failed_k !==
null) {
172 $this->
checkArg($which, $failed_k ===
null,
$m);
187 $classes = $this->
toArray($classes);
188 $this->
checkArgList($which, $values,
function ($_, $value) use (&$classes) {
189 foreach ($classes as $cls) {
190 if ($cls ===
"string" && is_string($value)) {
193 if ($cls ===
"int" && is_int($value)) {
195 } elseif ($value instanceof $cls) {
200 },
function ($_,
$failed) use (&$classes) {
213 if (is_array($value)) {
216 return array($value);
221 $type = gettype($value);
222 if (!is_object($value) && !is_array($value)) {
223 return "expected $expected, got $type '$value'";
225 if (is_object($value)) {
226 $type = get_class($value);
228 return "expected $expected, got $type";
An exception for terminatinating execution or to throw for unit testing.
getCanonicalName()
Get the canonical name of the component.
catch(Exception $e) $message
checkArgList($which, array &$values, \Closure $check, \Closure $message)
Check every key and value of the list with a supplied closure.
checkStringArg($which, $value)
Throw an InvalidArgumentException if $value is no string.
checkArg($which, $check, $message)
/** Throw an InvalidArgumentException containing the message if $check is false.
checkIntArg($which, $value)
Throw an InvalidArgumentException if $value is no int.
toArray($value)
Wrap the given value in an array if it is no array.
checkArgListElements($which, array &$values, &$classes)
Check every element of the list if it is an instance of one of the given classes.
wrongTypeMessage($expected, $value)
trait ComponentHelper
Provides common functionality for component implementations.
checkArgIsElement($which, $value, $array, $name)
Throw an InvalidArgumentException if $value is not an element of array.
checkFloatArg($which, $value)
Throw an InvalidArgumentException if $value is not a float.
checkArgInstanceOf($which, $value, $class)
Throw an InvalidArgumentException if $value is not an instance of $class.
getCanonicalNameByFullyQualifiedName()
Does the calculation required for getCanonicalName.