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

Add a shorthand for "getter" and "setter" on Objects #1312

Closed
ctippler opened this issue Feb 23, 2017 · 1 comment
Closed

Add a shorthand for "getter" and "setter" on Objects #1312

ctippler opened this issue Feb 23, 2017 · 1 comment
Assignees

Comments

@ctippler
Copy link
Contributor

Feature Request

Currently we often need to create getter/setter to get or set values by a field name.

                $fieldNames = ['field1','field2'];

                foreach($fieldNames as $field){
                    #currently
                    $value = $o->{"get".ucfirst($field)}();
                    #could be
                    $value = $o->get($field);
                }

Add a shorthand to get and set Values on objects by there field Name.

Add the following Code to the AbstractObject.php

/**
 * @param string $fieldName
 * @return mixed
 */
public function get($fieldName){
    return $this->{"get".ucfirst($fieldName)}();
}

/**
 * @param string $fieldName
 * @param $value
 * @return mixed
 */
public function set($fieldName,$value){
    return $this->{"set".ucfirst($fieldName)}($value);
}
@brusch
Copy link
Member

brusch commented Apr 9, 2018

Would be also good then to have them on localized fields and objects bricks (and maybe somewhere else?) - just to be consistent.

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

No branches or pull requests

3 participants