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

Synthetic properties support #6

Open
jakubkulhan opened this issue Sep 4, 2015 · 0 comments
Open

Synthetic properties support #6

jakubkulhan opened this issue Sep 4, 2015 · 0 comments
Labels

Comments

@jakubkulhan
Copy link
Contributor

Beside properties, it should be possible to annotate also getters and setters with annotations like @PhpArrayOffset, @JsonProperty etc. to support non-trivial cases.

Use cases:

  • properties as a functions of other properties
class User
{
    /** @var string */
    public $firstName;

    /** @var string */
    public $lastName;

    /**
     * @return string
     *
     * @PhpArrayOffset("name")
     */
    public function getName()
    {
        return sprintf("%s %s", $this->firstName, $this->lastName);
    }
}

$user = new User();
$user->firstName = "Jakub";
$user->lastName = "Kulhan";

UserMeta::toArray($user);
// ["firstName" => "Jakub", "lastName" => "Kulhan", "name" => "Jakub Kulhan"]
  • legacy property names
class Product
{
    /** @var string */
    public $description;

    /**
     * @return string
     *
     * @PhpArrayOffset("descr")
     */
    public function getDescr()
    {
        return $this->description;
    }
}
class Product
{
    /** @var Variant */
    public $variants;

    /**
     * @return TermGroup[]
     *
     * @PhpArrayOffset("term_groups")
     */
    public function getTermGroups()
    {
        // converts Variants to TermGroups
    }

    /**
     * @var TermGroup[]
     * @return void
     *
     * @PhpArrayOffset("term_groups")
     */
    public function setTermGroups($termGroups)
    {
        // converts TermGroups to Variants
    }
}
@jakubkulhan jakubkulhan added this to the 2.0 milestone Sep 4, 2015
@jakubkulhan jakubkulhan removed this from the 2.0 milestone Sep 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant