summaryrefslogtreecommitdiffstats
path: root/lib/route.php
blob: c5a8bd2aa363d5dea8b4d2d4a36197cbe5873119 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
 * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

use Symfony\Component\Routing\Route;

class OC_Route extends Route {
	public function method($method) {
		$this->setRequirement('_method', strtoupper($method));
		return $this;
	}

	public function post() {
		$this->method('POST');
		return $this;
	}

	public function get() {
		$this->method('GET');
		return $this;
	}

	public function put() {
		$this->method('PUT');
		return $this;
	}

	public function delete() {
		$this->method('DELETE');
		return $this;
	}

	public function defaults($defaults) {
		$action = $this->getDefault('action');
		$this->setDefaults($defaults);
		if (isset($defaults['action'])) {
			$action = $defaults['action'];
		}
		$this->action($action);
		return $this;
	}

	public function requirements($requirements) {
		$method = $this->getRequirement('_method');
		$this->setRequirements($requirements);
		if (isset($requirements['_method'])) {
			$method = $requirements['_method'];
		}
		if ($method) {
			$this->method($method);
		}
		return $this;
	}

	public function action($class, $function = null) {
		$action = array($class, $function);
		if (is_null($function)) {
			$action = $class;
		}
		$this->setDefault('action', $action);
		return $this;
	}

	public function actionInclude($file) {
		$function = create_function('$param', 'unset($param["_route"]);$_GET=array_merge($_GET,$param);unset($param);require_once "'.$file.'";');
		$this->action($function);
	}
}