prismicio-community / php-kit

Community maintained development kit for Prismic and the PHP language
https://prismic.io
Other
109 stars 83 forks source link

Introduce an abstract PrismicDataModel #5

Closed rande closed 11 years ago

rande commented 11 years ago

Hello,

The prismicio API is built on top of the magic method __get. It will be better to have proper getter and not relying on this feature. I guess this has been done to respect other api.

So in order to avoid duplicated code, it will be great to have a parent PrismicDataModel object to include this code. This will required to change property visibility from private to protected

<?php

abstract class PrismicDataModel 
{
    public function __get($property)
    {
        if (!property_exists($this, $property)) {
            throw new \RuntimeException(sprintf('The property %s on %s does not exist', $property, get_class($this));
        }

      return $this->$property;
    }
} 
dohzya commented 11 years ago

Thanks you for your suggestion :-)

You're perfectly right: proper getters should be used. The __get method has been used for convenience, but it should be replaced.

But I'm not so sure we need the PrismicDataModel abstract class:

So I close this issue because we won't introduce this abstract class (at least for now), and I created the issue #6 for the __get removal.

rande commented 11 years ago

amen