Neos\Flow\Persistence\AbstractPersistenceManager::convertObjectsToIdentityArrays PHP 메소드

convertObjectsToIdentityArrays() 공개 메소드

Recursively iterates through the given array and turns objects into an arrays containing the identity of the domain object.
public convertObjectsToIdentityArrays ( array $array ) : array
$array array The array to be iterated over
리턴 array The modified array without objects
    public function convertObjectsToIdentityArrays(array $array)
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $array[$key] = $this->convertObjectsToIdentityArrays($value);
            } elseif (is_object($value) && $value instanceof \Traversable) {
                $array[$key] = $this->convertObjectsToIdentityArrays(iterator_to_array($value));
            } elseif (is_object($value)) {
                $array[$key] = $this->convertObjectToIdentityArray($value);
            }
        }
        return $array;
    }

Usage Example

 /**
  * @test
  */
 public function convertObjectsToIdentityArraysConvertsObjectsInIterators()
 {
     $object1 = new \stdClass();
     $object2 = new \stdClass();
     $this->abstractPersistenceManager->expects($this->at(0))->method('getIdentifierByObject')->with($object1)->will($this->returnValue('identifier1'));
     $this->abstractPersistenceManager->expects($this->at(1))->method('getIdentifierByObject')->with($object2)->will($this->returnValue('identifier2'));
     $originalArray = ['foo' => 'bar', 'object1' => $object1, 'baz' => new \ArrayObject(['object2' => $object2])];
     $expectedResult = ['foo' => 'bar', 'object1' => ['__identity' => 'identifier1'], 'baz' => ['object2' => ['__identity' => 'identifier2']]];
     $actualResult = $this->abstractPersistenceManager->convertObjectsToIdentityArrays($originalArray);
     $this->assertEquals($expectedResult, $actualResult);
 }