2023/06/24: Difference between revisions

From Woozle Writes Code
Jump to navigation Jump to search
No edit summary
No edit summary
Line 33: Line 33:
So then we have the questions:
So then we have the questions:
* '''Q1''': From where is the string-value of <tt>$rec</tt> being retrieved?
* '''Q1''': From where is the string-value of <tt>$rec</tt> being retrieved?
** The list comes from <syntaxhighlight lang=php inline>$this->getPageList()</syntaxhighlight>
** ...and how that list is generated is... Complicated.
* '''Q2''': What is it ''supposed'' to be, if it's not a class name?
* '''Q2''': What is it ''supposed'' to be, if it's not a class name?

Revision as of 23:34, 24 June 2023

Saturday, June 24, 2023 (#175)
Friday Saturday Sunday

Notes

the problem flows like this: in this->getPage( $name ); we have

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 createObject( $spec, array $options = [] )</syntaxhiglight> calling <syntaxhighlight lang=php inline>static::getObjectFromSpec( $spec, $options ); which calls static::validateSpec( $spec, $options ); which then goes:

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 $this->objectFactory->createObject( $rec, /*...*/ ) if $rec is not a class name.

So then we have the questions:

  • Q1: From where is the string-value of $rec being retrieved?
    • The list comes from $this->getPageList()
    • ...and how that list is generated is... Complicated.
  • Q2: What is it supposed to be, if it's not a class name?