2023/06/24: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
* [https://github.com/wikimedia/mediawiki-libs-ObjectFactory/blob/3558d6630cefa60491e468965752651bc5bf3d3e/src/ObjectFactory.php#L177 ObjectFactory.php line 177] calls static::validateSpec( $spec, $options ); | * [https://github.com/wikimedia/mediawiki-libs-ObjectFactory/blob/3558d6630cefa60491e468965752651bc5bf3d3e/src/ObjectFactory.php#L177 ObjectFactory.php line 177] calls static::validateSpec( $spec, $options ); | ||
* [https://github.com/wikimedia/mediawiki-libs-ObjectFactory/blob/3558d6630cefa60491e468965752651bc5bf3d3e/src/ObjectFactory.php#L302 ObjectFactory.php line 302] is in validateSpec( $spec, array $options ), throws exception | * [https://github.com/wikimedia/mediawiki-libs-ObjectFactory/blob/3558d6630cefa60491e468965752651bc5bf3d3e/src/ObjectFactory.php#L302 ObjectFactory.php line 302] is in validateSpec( $spec, array $options ), throws exception | ||
the problem flows like this: in <syntaxhighlight lang=php inline>this->getPage( $name );</syntaxhighlight> we have | |||
<syntaxhighlight lang=php> | |||
if ( is_array( $rec ) || is_string( $rec ) || is_callable( $rec ) ) { | |||
$page = $this->objectFactory->createObject( $rec, [ 'allowClassName' => true,'allowCallable' => true ]); | |||
} | |||
</syntaxhighlight> | |||
...which implies that it should be perfectly okay to call createObject() with a string, but then we have <syntaxhighlight lang=php inline>createObject( $spec, array $options = [] )</syntaxhiglight> calling <syntaxhighlight lang=php inline>static::getObjectFromSpec( $spec, $options );</syntaxhighlight> which calls <syntaxhighlight lang=php inline>static::validateSpec( $spec, $options );</syntaxhighlight> which then goes: | |||
<syntaxhighlight lang=php> | |||
if ( is_string( $spec ) && class_exists( $spec ) ) { | |||
if ( empty( $options['allowClassName'] ) ) { | |||
throw new InvalidArgumentException('Passing a raw class name is not allowed here. Use [ \'class\' => $classname ] instead.'); | |||
} | |||
return [ 'class' => $spec ]; | |||
} | |||
if ( !is_array( $spec ) ) { | |||
throw new InvalidArgumentException( 'Provided specification is not an array.' ); | |||
} | |||
</syntaxhighlight> | |||
...so I ''think'' what I'm getting from that is that it's only okay to call <syntaxhighlight lang=php inline>$this->objectFactory->createObject( $rec, /*...*/ )</syntaxhighlight> if <tt>$rec</tt> is ''not'' a class name. | |||
So then we have the questions: | |||
* '''Q1''': From where is the string-value of <tt>$rec</tt> being retrieved? | |||
* '''Q2''': What is it ''supposed'' to be, if it's not a class name? |
Revision as of 23:21, 24 June 2023
Saturday, June 24, 2023 (#175)
|
Notes
the problem flows like this: in if ( is_array( $rec ) || is_string( $rec ) || is_callable( $rec ) ) {
$page = $this->objectFactory->createObject( $rec, [ 'allowClassName' => true,'allowCallable' => true ]);
}
...which implies that it should be perfectly okay to call createObject() with a string, but then we have if ( is_string( $spec ) && class_exists( $spec ) ) {
if ( empty( $options['allowClassName'] ) ) {
throw new InvalidArgumentException('Passing a raw class name is not allowed here. Use [ \'class\' => $classname ] instead.');
}
return [ 'class' => $spec ];
}
if ( !is_array( $spec ) ) {
throw new InvalidArgumentException( 'Provided specification is not an array.' );
}
...so I think what I'm getting from that is that it's only okay to call So then we have the questions:
|