daves-weblab / rest-bundle

Bundle for creating REST Apis for Pimcore Objects for REST and JsonApi Json Standards.
3 stars 0 forks source link

Updated object reader to use the fully qualified namespace rather than the name of the class only #4

Open mcuenez opened 6 years ago

mcuenez commented 6 years ago

Why change?

By doing so, it is possible to keep the namespace restriction, while avoiding harcoded strings as class name. Furthermore, IDEs like PHPStorm can now jump to the specified class, using the corresponding shortcuts.

Usage

Basically, the usage does not differ much, only the namespace needs to be provided. This means that either MyModel::class or "\Namespace\To\MyModel" can be used instead of "MyModel" only. While the latter seems to be of disadvantage as it requires additional information passed by the user, the former is the intended way to go. Not only because of the aforementioned reasons, but also because the code has increased readability and maintainability.

/**
 * @inheritdoc
 */
protected function getClassName()
{
    return MyModel::class;
}

Additional Information

A proper exception was added to notify the programmer about invalid classes in use.