XF\Mvc\Entity\Manager::getFinder does not always return a Finder

Xon

Well-known member
Affected version
2.2.10
The XF\Mvc\Entity\Manager::getFinder function is type hinted to return a finder, but if an add-on does not implement the entity name as a short-string, this will fail and instead return the entity.

This will then give a misleading missing function message quite some distance from the root-cause.

Reproducer:

PHP:
namespace MyAddon\Entity;
class MyEntity extends \XF\Mvc\Entity\Entity
{
    public static function getStructure(Structure $structure): Structure
    {
        $structure->table = 'xf_my_table';
        $structure->shortName = 'MyAddon:MyEntity';
        $structure->primaryKey = 'id';
        $structure->columns = [
            'id' =>['type' => self::UINT, 'autoIncrement' => true, 'nullable' => true],
        ];
        return $structure;
    }
}
When the content_type_field entity has the value of MyAddon\Entity\MyEntity then getFinder will return an entity instead of the expected finder.

This is because of the following code:
PHP:
        $finderClass = $this->extension->extendClass($finderClass, '\XF\Mvc\Entity\Finder');
        if (!$finderClass || !class_exists($finderClass))
        {
            $finderClass = '\XF\Mvc\Entity\Finder';
        }
        /** @var Finder $finder */
        $finder = new $finderClass($this, $structure);
There is no validation that $finder is of the expected type.
 
Back
Top Bottom