public function test_callback() { $callback = 'foo::bar(one,two,three)'; // The valid callback and params $expect = array(array('foo', 'bar'), array('one', 'two', 'three')); $this->assert_equal(Arr::callback($callback), $expect); }
/** * Tests Arr::callback() * * @test * @dataProvider provider_callback * @param string $str String to parse * @param array $expected Callback and its parameters */ public function test_callback($str, $expected) { $result = Arr::callback($str); $this->assertSame(2, count($result)); $this->assertSame($expected, $result); }
/** * Bulk updates * * @param array $post * @uses Post::bulk_actions * @uses Arr::callback */ private function _bulk_update($post) { $operations = Post::bulk_actions(FALSE, 'blog'); $operation = $operations[$post['operation']]; $blogs = array_filter($post['blogs']); // Filter out unchecked pages if ($operation['callback']) { list($func, $params) = Arr::callback($operation['callback']); if (isset($operation['arguments'])) { $args = array_merge(array($blogs), $operation['arguments']); } else { $args = array($blogs); } // set model name $args['type'] = 'blog'; // execute the bulk operation call_user_func_array($func, $args); } }
/** * Performs a callback on the error * * @param array $options Options from config * @return void */ protected function _action_callback(array $options = array()) { $callback = Arr::get($options, 'callback'); @list($method,) = Arr::callback($callback); if (is_callable($method)) { call_user_func($method, $this); } }
/** * Bulk update * * Executes the bulk operation * * @param array $post Array of comments * @uses Comment::bulk_actions * @uses Arr::callback * @uses Arr::merge */ private function _bulk_update($post) { // Filter out unchecked comments $comments = array_filter($post['comments']); $operations = Comment::bulk_actions(FALSE); $operation = $operations[$post['operation']]; if ($operation['callback']) { list($func, $params) = Arr::callback($operation['callback']); if (isset($operation['arguments'])) { $args = Arr::merge(array($comments), $operation['arguments']); } else { $args = array($comments); } // Execute the bulk operation call_user_func_array($func, $args); } }