コード例 #1
0
 /**
  * Defined by Zend_Filter_Interface
  *
  *
  * @param  mixed $value
  * @return integer
  */
 public function filter($value)
 {
     if ($this->_root != null) {
         if (!array_key_exists(0, $value)) {
             return $value;
         }
         if (!array_key_exists($this->_root, $value[0])) {
             return $value;
         }
         $value = $value[0][$this->_root];
     }
     if (!is_array($value)) {
         return $value;
     }
     /**
      * @see Conjoon_Util_Array
      */
     require_once 'Conjoon/Util/Array.php';
     if (isset($value[0]) && is_array($value[0]) && count($value) == 1 && !Conjoon_Util_Array::isAssociative($value[0])) {
         return $value[0];
     }
     if (Conjoon_Util_Array::isAssociative($value)) {
         return array($value);
     }
     return $value;
 }
コード例 #2
0
ファイル: ExtRequest.php プロジェクト: ThorstenSuckow/conjoon
 /**
  * Refreshes the parameter list for the specified request.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param Array $params
  */
 protected function _applyParams(Zend_Controller_Request_Abstract $request, array $data)
 {
     $rData = empty($data['data']) ? array() : $data['data'];
     if (!Conjoon_Util_Array::isAssociative($rData)) {
         $request->setParam('data', $rData);
     } else {
         $request->setParams($rData);
     }
     unset($data['data']);
     $request->setParam($this->_config['extParameter'], $data);
 }
コード例 #3
0
ファイル: Decorator.php プロジェクト: ThorstenSuckow/conjoon
 /**
  * Tries to cast a numeric/associative array into it's representant
  * entity model as defined in $_entity.
  *
  * @param array $data The array data, if numeric, a numeric array
  * will be returned, with values of the type $className. If an
  * associative array was submitted, a single object of the type
  * $className will be returned.
  *
  * @return mixed Either an array of objects or a single object.
  */
 protected final function _cast($values, $type)
 {
     if ($values instanceof Zend_Db_Table_Rowset_Abstract || $values instanceof Zend_Db_Table_Row_Abstract || is_object($values) && method_exists($values, 'toArray')) {
         $values = $values->toArray();
     }
     if (!is_array($values) || $type == self::TYPE_ARRAY) {
         return $values;
     }
     $len = count($values);
     if ($len == 0) {
         return array();
     }
     $entity = $this->_entity;
     // simple check to determine if we have a assoc or numeric
     // array
     if (!Conjoon_Util_Array::isAssociative($values)) {
         $data = array();
         $TYPE_DTO = $type == self::TYPE_DTO;
         for ($i = 0; $i < $len; $i++) {
             Conjoon_Util_Array::camelizeKeys($values[$i]);
             if ($this->_filter) {
                 $values[$i] = $this->_filter->setData($values[$i])->getProcessedData();
             }
             $data[] = Conjoon_BeanContext_Inspector::create($entity, $values[$i], !$this->_strict);
             if ($TYPE_DTO) {
                 $data[$i] = $data[$i]->getDto();
                 if ($this->_filter) {
                     $vv =& $values[$i];
                     $dd =& $data[$i];
                     $props = get_class_vars(get_class($data[$i]));
                     foreach ($props as $propname => $propvalue) {
                         if (!array_key_exists($propname, $vv)) {
                             unset($dd->{$propname});
                         }
                     }
                 }
             }
         }
         return $data;
     } else {
         Conjoon_Util_Array::camelizeKeys($values);
         if ($this->_filter) {
             $values = $this->_filter->setData($values)->getProcessedData();
         }
         $data = Conjoon_BeanContext_Inspector::create($entity, $values, !$this->_strict);
         if ($type == self::TYPE_DTO) {
             return $data->getDto();
         }
         return $data;
     }
 }