addMethod() public static method

Add a custom user method via closure or PHP callback
public static addMethod ( string $method, callable $callback )
$method string Method name to add
$callback callable Callback or closure that will be executed when missing method call matching $method is made
Example #1
0
 public function testQueryPagerExtension()
 {
     $mapper = test_spot_mapper();
     \Spot\Query::addMethod('page', function (\Spot\Query $query, $limit, $perPage = 20) {
         return $query->limit($limit, $perPage);
     });
     $posts = $mapper->all('\\Spot\\Entity\\Post')->page(1, 1);
     // Do this instead of $posts->count() because it drops LIMIT clause to count the full dataset
     $postCount = count($posts->toArray());
     $this->assertEquals(1, $postCount);
 }