Pop\Pdf\Import::shiftObjects PHP Метод

shiftObjects() публичный Метод

Method to shift the objects' indices based on the array of indices passed to the method, to prevent duplication.
public shiftObjects ( integer $si ) : void
$si integer
Результат void
    public function shiftObjects($si)
    {
        if ($this->firstIndex($this->objects) <= $si) {
            ksort($this->objects);
            $keyChanges = array();
            $newObjects = array();
            foreach ($this->objects as $key => $value) {
                $keyChanges[$key] = $si;
                $newObjects[$si] = $this->objects[$key];
                if (substr($newObjects[$si]['data'], 0, strlen($key . ' 0 obj')) === $key . ' 0 obj') {
                    $newObjects[$si]['data'] = str_replace($key . ' 0 obj', $si . ' 0 obj', $newObjects[$si]['data']);
                }
                $si++;
            }
            $keyChanges = array_reverse($keyChanges, true);
            foreach ($newObjects as $key => $obj) {
                if (count($obj['refs']) > 0) {
                    $matches = array();
                    preg_match_all('/\\d+\\s0\\sR/mi', $newObjects[$key]['data'], $matches, PREG_OFFSET_CAPTURE);
                    if (isset($matches[0][0])) {
                        $start = count($matches[0]) - 1;
                        for ($i = $start; $i >= 0; $i--) {
                            $ref = $matches[0][$i][0];
                            $len = $matches[0][$i][1];
                            $k = substr($ref, 0, strpos($ref, ' '));
                            if (isset($keyChanges[$k])) {
                                $newObjects[$key]['data'] = substr_replace($newObjects[$key]['data'], $keyChanges[$k] . ' 0 R', $len, strlen($ref));
                            }
                        }
                    }
                }
            }
            foreach ($this->pages as $k => $v) {
                if (isset($keyChanges[$v])) {
                    $this->kids[$k] = $keyChanges[$v];
                }
            }
            $this->objects = $newObjects;
            $this->pages = $this->kids;
        }
    }

Usage Example

Пример #1
0
 public function testShiftObjects()
 {
     $i = new Import(__DIR__ . '/../tmp/test.pdf');
     $i->shiftObjects(5);
     $this->assertInstanceOf('Pop\\Pdf\\Import', $i);
     $this->assertTrue(is_array($i->returnObjects(2)));
 }
All Usage Examples Of Pop\Pdf\Import::shiftObjects