     1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

    <?php
    namespace Catapult;
    /**
     * Forms a new object by both modifiying
     * new object given
     * context by first
     * passing it data to its internal method
     * objects MUST have a
     * set_up, set or setup method
     * 'Borrowed' from Python version
     * this should also keep things
     * neat by switching the 'current'
     * objects state
     */
    class Constructor {

        /**
         * Pass two objects, the current and new
         * current should be a reference and determine
         * its new properties. New object
         * should be made seperate
         */
        public static function Make(&$object, $data=array(), $reload=false)
        {
          foreach ($data as $k => $d) {
            $object->$k = $d;
            $checked = true;
           }

           if (!$checked) Throw new \CatapultApiException(EXCEPTIONS::EXCEPTION_OBJECT_DATA . $object->__CLASS__);

            /* get the full
             * properties of the
             * object incase we havent
             */

            if (isset($object->schema)) {
              foreach ($object->schema->needs as $field) {
                if (isset($object->schema->{$field}) && (!($object->schema->{$field} != null || isset($object->schema->{$field})))) {
                  $object = $object->get($object->id);
                }
               }
             }

            /** this assumes the object knows its id **/
            if ($reload) {
              $object = $object->get();
            }

            return $object;
        }

        /**
        * IF we've found setup, set_up or set
        * set the check as true
        * otherwise don't call
        * @param object: Resource Object
        * @param t:  T
        * @param d -> D
        */
        public function check($object,$t,&$d)
        {
          $this->checked = true;

          return $object;
        }

       /**
        * Constructor's find will merely
        * check if this class is available
        * if it return. Otherwise throw warning
        *
        * @param class: Catapult namespace class
        */
        public function find($class)
        {
          if (!get_class($class)) {
            // todo
            // this is not needed. throw a warning or error
          }

          return $class;
        }
    }