1 Reply Latest reply on Jun 7, 2011 10:03 PM by jaco_graaff

    more robust usage of value objects in php


      To be able to use some of the more advanced features of flashbuilder for php I followed the tutorials. The problem with automated processes is that it creates a lot of extra ubiquitous code. In the past I have used amfPHP and manually created my mapping data objects in flash builder - but want to try and use a more "industry-standard" and scalable approach.


      in my php-services file, e.g. customerServices.php - I have a class defining the VO - mapping the table-columns to a php object. Then I also have the services - the CRUD functions to create, read, update and delete. Now I want to GET or CREATE data from the database but I don't want to use ALL of the columns/properties of my object all the time - e.g. the primary key (id), or values like CREATION_DATE that will be filled with CURRENT_TIMESTAMP and other properties are not neccessary. I want to read the id and timestamp so I need to declare it in my VO - but I do not need it for writing. The PHP class looks for it  though because I am refering to the same VO-class.

      My PHP VO wants me to pass all of the values to the __construct(stdClass $customer) constructer - How do i pick and choose without creating different Value Object classes - e.g. fullVO, basicVO, someOhterUseVO.


      Can someone maybe guide me in some direction - if have tried to dynamically declare the properties of the VO - but then it breaks the connectivity to the fancy new feautures (LIKE "Test Operation") in fleash builder - which means I could just as well do it all in the old way...



        • 1. Re: more robust usage of value objects in php
          jaco_graaff Level 1

          The answer lies in the way I declare/instanciate my properties in my VO -


          I want to "overload" my object class


          The usage of getters and setters rather than setting the values in the __construct() function of the value object class




          Regardless of the simplicity of the above example, it demonstrates how useful the "__set()" and "__get()" magic functions can be when it comes to overloading properties of a class. - from the devshed article


          In the mean time - to get my demo up and running - instead of using the following (refering to the MODEL of client)



           public function createClient(stdClass $client) {      
                    # Zend Framework Zend_Db likes arrays of data, not objects
                    $data = $this->toArray($client);
                    # Equivalent SQL statement: "INSERT INTO employees (first_name, last_name, gender, birth_date,
                    # hire_date) VALUES ($employe->first_name, $employe->last_name, $employe->gender, 
                    # $employe->birth_date, $employe->hire_date)";
                    $this->db->insert('user', $data);
                    # Return the last value generated by an auto-increment column
                    return $this->db->lastInsertId();


          I use


           public function createNewBasicClient($object)
               //$object = {name:"Keeran",  surname:"Doodle",  username:"keeran",  password:"doodle"}
               //cast custom object to an array
               $this->db->insert('user', (array)$object); 
               return ($this->db->lastInsertId());

          in this way object could be anything - although I am not using my nice MODEL anymore


          It will take me a bit longer to get the __get __set way figured out though