Tablica obiektów

0

Mam w zmiennej $tab tablicę obiektów, której print_r() wygląda tak (początek):

Array
(
    [5] => SeedDMS_Core_Attribute Object
        (
            [_id:protected] => 43
            [_obj:protected] => SeedDMS_Core_Document Object
                (
                    [_name:protected] => AU665 ANEKS NR 1 DO UMOWY CESJI WIERZYTELNOŚCI 50% OD ODZYSKANYCH KWOT I 100% OD ODSETEK
                    [_comment:protected] => 
                    [_date:protected] => 1489147282
                    [_ownerID:protected] => 6
                    [_folderID:protected] => 55
                    [_expires:protected] => 1435615200
                    [_inheritAccess:protected] => 1
                    [_defaultAccess:protected] => 2

Pytanie: jak się dobrać do elementu np. **[_expires:protected] ** aby można go wyświetlić albo wsadzić do zmiennej??
Dziękuję za odpowiedź :)

1

Patrząc po drzewie struktury to rzekłbym
$array[5]->__obj->__expires

Przyjrzyj się przykładowi

class obj1
{
  private  $attribute;

    /**
     * obj1 constructor.
     * @param $attribute
     */
    public function __construct($attribute)
    {
        $this->attribute = $attribute;
    }

    /**
     * @return mixed
     */
    public function getAttribute()
    {
        return $this->attribute;
    }


}

class obj2
{
    private $obj1=[];


    /**
     * @param array|obj1 $obj1
     * @return $this
     */
    public function setObj1(obj1 $obj1)
    {
        $this->obj1[] = $obj1;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getObj1()
    {
        return $this->obj1;
    }
}


$array=[];
foreach (range(1,10)as $item)
{
    $obj2=new obj2;
    $array[]= $obj2->setObj1((new obj1('honda')));
}
print_r($array);

echo $array[1]->getObj1()[0]->getAttribute()

Przy strukturze

(
    [0] => obj2 Object
        (
            [obj1:obj2:private] => Array
                (
                    [0] => obj1 Object
                        (
                            [attribute:obj1:private] => honda
                        )

                )

        )

    [1] => obj2 Object
        (
            [obj1:obj2:private] => Array
                (
                    [0] => obj1 Object
                        (
                            [attribute:obj1:private] => honda
                        )

                )

        )

)

echo $array[1]->getObj1()[0]->getAttribute()
0

Zrobić getter, albo przez refleksję jakoś.

2

Obiekt klasy SeedDMS_Core_Document trafia do obiektu klasy SeedDMS_Core_Attribute w konstruktorze.

/**
 * Constructor
 *
 * @param integer $id internal id of attribute
 * @param SeedDMS_Core_Object $obj object this attribute is attached to
 * @param SeedDMS_Core_AttributeDefinition $attrdef reference to the attribute definition
 * @param string $value value of the attribute
 */
function SeedDMS_Core_Attribute($id, $obj, $attrdef, $value) { /* {{{ */
    $this->_id = $id;
    $this->_obj = $obj;
    $this->_attrdef = $attrdef;
    $this->_value = $value;
    $this->_dms = null;
}

Co ważniejsze klasa SeedDMS_Core_Attribute nie ma gettera pozwalającego ten obiekt wydobyć (pole _obj jest protected)

Z dokumentacji wynika, że _obj to

folder, document or document content this attribute belongs to

więc masz dwa wyjśćia:

  1. Brute force - wydrzeć to pole za pomocą ReflectionClass - ale nie polecam. Bo wtedy sam sie prosisz o kuku,
  2. Spróbować ustrzelić ten dokument, który jest przekazywany do obiektu klasy SeedDMS_Core_Attribute wcześniej.
0
Desu napisał(a):

Obiekt klasy SeedDMS_Core_Document trafia do obiektu klasy SeedDMS_Core_Attribute w konstruktorze.

/**
 * Constructor
 *
 * @param integer $id internal id of attribute
 * @param SeedDMS_Core_Object $obj object this attribute is attached to
 * @param SeedDMS_Core_AttributeDefinition $attrdef reference to the attribute definition
 * @param string $value value of the attribute
 */
function SeedDMS_Core_Attribute($id, $obj, $attrdef, $value) { /* {{{ */
    $this->_id = $id;
    $this->_obj = $obj;
    $this->_attrdef = $attrdef;
    $this->_value = $value;
    $this->_dms = null;
}

Co ważniejsze klasa SeedDMS_Core_Attribute nie ma gettera pozwalającego ten obiekt wydobyć (pole _obj jest protected)

Z dokumentacji wynika, że _obj to

folder, document or document content this attribute belongs to

więc masz dwa wyjśćia:

  1. Brute force - wydrzeć to pole za pomocą ReflectionClass - ale nie polecam. Bo wtedy sam sie prosisz o kuku,
  2. Spróbować ustrzelić ten dokument, który jest przekazywany do obiektu klasy SeedDMS_Core_Attribute wcześniej.

Wyjaśniłeś dosadnie, aczkolwiek i tak nie wiem jak to ugryźć...tzn muszę pomyśleć.
Jak nie pójdzie tak to skonstruuję zapytanie do bazy i wyjdzie chyba najprościej :)

Dzięki wielkie!

1 użytkowników online, w tym zalogowanych: 0, gości: 1