Piwik\BaseFactory::factory PHP Метод

factory() публичный статический Метод

Creates a new instance of a class using a string ID.
public static factory ( string $classId ) : Piwik\DataTable\Renderer
$classId string The ID of the class.
Результат Piwik\DataTable\Renderer
    public static function factory($classId)
    {
        $className = static::getClassNameFromClassId($classId);
        if (!class_exists($className)) {
            self::sendPlainHeader();
            throw new Exception(static::getInvalidClassIdExceptionMessage($classId));
        }
        return new $className();
    }

Usage Example

Пример #1
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Invalid class ID
  */
 public function testCreatingInvalidClassThrows()
 {
     BaseFactory::factory("This\\Class\\Does\\Not\\Exist");
 }