annotate classes/loader.php @ 116:0ef426b5a1b9 extractapp

replace delimit character from "tab" to "comma"
author Calvin Yeh <cyeh@mpiwg-berlin.mpg.de>
date Thu, 28 Sep 2017 17:43:13 +0200
parents f1f849d31272
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
2 /*
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
3 * loader.php
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
4 * This file is part of Extraction-interface.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
5 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
6 * Extraction-interface is free software: you can redistribute it and/or modify
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
7 * it under the terms of the GNU General Public License as published by
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
8 * the Free Software Foundation, either version 3 of the License, or
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
9 * (at your option) any later version.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
10 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
11 * Extraction-interface is distributed in the hope that it will be useful,
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
14 * GNU General Public License for more details.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
15 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
16 * You should have received a copy of the GNU General Public License
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
17 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
18 */
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
19
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
20 /**
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
21 * Loader is used to route parameters from input url and set parameters for controller.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
22 * The routing is done by the RewriteRule written in .htaccess file.
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
23 */
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 class Loader {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 private $controller;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 private $action;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 private $urlvalues;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 private $postdata = 0;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
30
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 public function __construct($urlvalues, $postdata) {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
32 /**
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
33 * It stores parameters in URL on object creation.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
34 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
35 * For example, the URL structure is like this: some_domain_name/Extractapp/TaggingText.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
36 * The controller is "Extractapp" and the action is "TaggingText".
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
37 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
38 * For the "Extractapp" controller, there is a corresponding "extractapp.php" in "./controllers" folder.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
39 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
40 * For the action "TaggingText", there is a corresponding "TaggingText.php" in "./views/Extractapp" folder.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
41 *
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
42 * Under "./view" folder, the first level of the sub-folder is named by the controller's name.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
43 * Each action controlled by the controller has it's own php file. The file name is the same as the the action's name.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
44 */
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
45
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 $this->urlvalues = $urlvalues;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 $this->postdata = $postdata;
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 if ($this->urlvalues['controller'] == "") {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
49 $this->controller = "Extractapp"; // the default controller
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
50
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 $this->controller = $this->urlvalues['controller'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55 if ($this->urlvalues['action'] == "") {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
56 $this->action = "TaggingText"; // the default action
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
57
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
59 $this->action = $this->urlvalues['action'];
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
60 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 public function CreateController() {
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
64 /**
81
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
65 * Establish the requested controller as an object, and check if the query is valid.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
66 * The queried controller, which should be extended from BaseController, exists and the queried action should be one of its method.
f1f849d31272 book_id as string
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 77
diff changeset
67 */
77
97c1e5102a22 New: export table for a file from LGService
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 47
diff changeset
68
47
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
69 //does the class exist?
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 if (class_exists($this->controller)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
71 $parents = class_parents($this->controller);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 //does the class extend the controller class?
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
73 if (in_array("BaseController",$parents)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
74 //does the class contain the requested method?
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
75 if (method_exists($this->controller,$this->action)) {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
76 return new $this->controller($this->action,$this->urlvalues,$this->postdata);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
77 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 //bad method error
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 return new Error("badUrl",$this->urlvalues);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
82 //bad controller error
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 return new Error("badUrl",$this->urlvalues);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
84 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 } else {
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
86 //bad controller error
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 return new Error("badUrl",$this->urlvalues);
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
88 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
89 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 }
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
91
886f43b26ee2 move/remove develop folder
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 ?>