Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
shanliu committed Jul 23, 2020
1 parent 0587cf4 commit ab6048c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
19 changes: 17 additions & 2 deletions ext/src/class_entity_set.c
Expand Up @@ -120,9 +120,10 @@ ZEND_METHOD(lsentity_entity_set_class, asArray){
object = getThis();
zval result;
array_init(&result);
zend_call_method_with_0_params(object,Z_OBJCE_P(object),NULL,"rewind",NULL);


zval keey_key;
zend_call_method_with_0_params(object,Z_OBJCE_P(object),NULL,"key",&keey_key);
zend_call_method_with_0_params(object,Z_OBJCE_P(object),NULL,"rewind",NULL);

if((!key||ZSTR_LEN(key)<=1)&&(!value||ZSTR_LEN(value)<=1)){
while (lsentity_check_bool_with_0_params(object,"valid")){
Expand Down Expand Up @@ -202,6 +203,20 @@ ZEND_METHOD(lsentity_entity_set_class, asArray){
zval_ptr_dtor(&zkey);
zval_ptr_dtor(&zvalue);
}
zend_call_method_with_0_params(object,Z_OBJCE_P(object),NULL,"rewind",NULL);
while (lsentity_check_bool_with_0_params(object,"valid")){
zval stkey,sres;
zend_call_method_with_0_params(object,Z_OBJCE_P(object),NULL,"key",&stkey);
if(is_equal_function(&sres,&stkey,&keey_key)==SUCCESS){
zval_ptr_dtor(&stkey);
zval_ptr_dtor(&sres);
break;
}
zval_ptr_dtor(&stkey);
zval_ptr_dtor(&sres);
zend_call_method_with_0_params(object,Z_OBJCE_P(object),NULL,"next",NULL);
}
zval_ptr_dtor(&keey_key);
RETURN_ZVAL(&result,1,1);
}
ZEND_METHOD(lsentity_entity_set_class, current){
Expand Down
4 changes: 2 additions & 2 deletions src/classes/LSYS/Entity/ColumnSet.php
Expand Up @@ -59,13 +59,13 @@ public function asArray($type){
return array_keys($this->_columns);
case self::TYPE_DEFAULT:
$out=array();
foreach ($this as $k=>$v){
foreach ($this->_columns as $k=>$v){
$out[$k]=$v->getDefault();
}
return $out;
case self::TYPE_ARRAY:
$out=array();
foreach ($this as $k=>$v){
foreach ($this->_columns as $k=>$v){
$out[$k]=$v->asArray();
}
return $out;
Expand Down
6 changes: 6 additions & 0 deletions src/classes/LSYS/Entity/EntitySet.php
Expand Up @@ -52,6 +52,8 @@ public function valid()
}
public function asArray( $key = NULL, $value = NULL)
{
$keep_key=$this->key();
$this->rewind();
$results = array();

if ($key === NULL AND $value === NULL)
Expand Down Expand Up @@ -87,6 +89,10 @@ public function asArray( $key = NULL, $value = NULL)
}
}
$this->rewind();
while (true) {
if(!$this->valid()||$this->key()==$keep_key)break;
$this->next();
}
return $results;
}
/**
Expand Down

0 comments on commit ab6048c

Please sign in to comment.