Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'public_method' access requires redundant property in class #280

Closed
calumbrodie opened this issue Mar 18, 2013 · 5 comments
Closed

'public_method' access requires redundant property in class #280

calumbrodie opened this issue Mar 18, 2013 · 5 comments

Comments

@calumbrodie
Copy link

I'm finding that with a configuration like so:

Namespace\Bundle\CategoryBundle\Entity\Category:
  exclusion_policy: ALL
  properties:
    type:
      expose: true
      access_type: public_method
      type: string
      accessor:
        getter: getType
        setter: setType

The serialized entity does not contain this 'computed' property - unless I add the named property to my class..

eg This works:

<?php

class Category implements CategoryInterface
{

        protected $type;            

    public function getType()
    {
        return 'typeA'
    }

    public function setType($type)
    {
        throw new \Exception('type is a read only property');
    }

}

And this doesn't

<?php

class Category implements CategoryInterface
{

    public function getType()
    {
        return 'typeA'
    }

    public function setType($type)
    {
        throw new \Exception('type is a read only property');
    }

}
@calumbrodie
Copy link
Author

Having read the documentation here: http://jmsyst.com/libs/serializer/master/reference/annotations#accessor

I guess this is expected behaviour. It just seems a bit redundant to set a property that is not required - however I'll move to close this issue as it's not a big deal.

@stof
Copy link
Contributor

stof commented Mar 18, 2013

What you need for your use case is @VirtualProperty, not the accessor

@stof
Copy link
Contributor

stof commented Mar 18, 2013

@schmittjoh @VirtualProperty does not seem to be documented. Is it intended ?

@calumbrodie
Copy link
Author

Thanks stof - this is absent from the documentation - but for anyone else reading the relevant PR is here:

#109

If I get time I'll make a PR to update the docs

Edit: x-posted

@schmittjoh
Copy link
Owner

@stof, no, that is not intended :)

On Mon, Mar 18, 2013 at 4:06 PM, Christophe Coevoet <
[email protected]> wrote:

@schmittjoh https://github.com/schmittjoh @VirtualProperty does not
seem to be documented. Is it intended ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/280#issuecomment-15059840
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants