Phalcon\Paginator\Pager::getLayout PHP Method

getLayout() public method

Returns the layout object.
public getLayout ( ) : Layout
return Phalcon\Paginator\Pager\Layout
    public function getLayout()
    {
        if (!array_key_exists('layoutClass', $this->options)) {
            $this->options['layoutClass'] = 'Phalcon\\Paginator\\Pager\\Layout';
        }
        if (!array_key_exists('urlMask', $this->options)) {
            throw new \RuntimeException('You must provide option "urlMask"');
        }
        $range = null;
        $rangeClass = $this->getRangeClass();
        $rangeLength = $this->getRangeLength();
        if (!class_exists($rangeClass)) {
            throw new \RuntimeException(sprintf('Unable to find range class "%s"', $rangeClass));
        }
        if (!class_exists($this->options['layoutClass'])) {
            throw new \RuntimeException(sprintf('Unable to find layout "%s"', $this->options['layoutClass']));
        }
        return new $this->options['layoutClass']($this, new $rangeClass($this, $rangeLength), $this->options['urlMask']);
    }

Usage Example

Example #1
1
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Unable to find layout "UnknownLayoutClass"
  */
 public function testGetLayoutMethodShouldWithInvalidLayoutClassShouldThrowException()
 {
     // stub paginate
     $paginate = new stdClass();
     $paginate->total_pages = 20;
     $paginate->current = 1;
     $mock = Mockery::mock(self::BUILDER_CLASS);
     $mock->shouldReceive('getPaginate')->once()->andReturn($paginate);
     $mock->shouldReceive('getLimit')->once()->andReturn(null);
     $pager = new Pager($mock, ['rangeLength' => 5, 'layoutClass' => 'UnknownLayoutClass', 'urlMask' => 'xxx']);
     $pager->getLayout();
 }