1
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.'); |
2
|
|
|
|
3
|
|
|
class Kodoc_Controller extends Template_Controller |
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
// Do not allow to run in production |
7
|
|
|
const ALLOW_PRODUCTION = false; |
8
|
|
|
|
9
|
|
|
public $template = 'kodoc/template'; |
10
|
|
|
|
11
|
|
|
// Kodoc instance |
12
|
|
|
protected $kodoc; |
13
|
|
|
|
14
|
|
|
public function __construct() |
15
|
|
|
{ |
16
|
|
|
parent::__construct(); |
17
|
|
|
|
18
|
|
|
$active = $this->uri->segment(2) ? $this->uri->segment(2) : 'core'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
// Add the menu to the template |
21
|
|
|
$this->template->menu = new View('kodoc/menu', array('active' => $active)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function index() |
25
|
|
|
{ |
26
|
|
|
$this->template->content = 'hi'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function media() |
30
|
|
|
{ |
31
|
|
|
if (isset($this->profiler)) { |
32
|
|
|
$this->profiler->disable(); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// Get the filename |
36
|
|
|
$file = implode('/', $this->uri->segment_array(1)); |
37
|
|
|
$ext = strrchr($file, '.'); |
38
|
|
|
|
39
|
|
|
if ($ext !== false) { |
40
|
|
|
$file = substr($file, 0, -strlen($ext)); |
41
|
|
|
$ext = substr($ext, 1); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Disable auto-rendering |
45
|
|
|
$this->auto_render = false; |
46
|
|
|
|
47
|
|
|
try { |
48
|
|
|
// Attempt to display the output |
49
|
|
|
echo new View('kodoc/'.$file, null, $ext); |
50
|
|
|
} catch (Kohana_Exception $e) { |
|
|
|
|
51
|
|
|
Event::run('system.404'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function __call($method, $args) |
56
|
|
|
{ |
57
|
|
|
if (count($segments = $this->uri->segment_array(1)) > 1) { |
58
|
|
|
// Find directory (type) and filename |
59
|
|
|
$type = array_shift($segments); |
60
|
|
|
$file = implode('/', $segments); |
61
|
|
|
|
62
|
|
|
if (substr($file, -(strlen(EXT))) === EXT) { |
63
|
|
|
// Remove extension |
64
|
|
|
$file = substr($file, 0, -(strlen(EXT))); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if ($type === 'config') { |
68
|
|
|
if ($file === 'config') { |
69
|
|
|
// This file can only exist in one location |
70
|
|
|
$file = APPPATH.$type.'/config'.EXT; |
71
|
|
|
} else { |
72
|
|
|
foreach (array_reverse(Kohana::include_paths()) as $path) { |
73
|
|
|
if (is_file($path.$type.'/'.$file.EXT)) { |
74
|
|
|
// Found the file |
75
|
|
|
$file = $path.$type.'/'.$file.EXT; |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} else { |
81
|
|
|
// Get absolute path to file |
82
|
|
|
$file = Kohana::find_file($type, $file); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (in_array($type, Kodoc::get_types())) { |
86
|
|
|
// Load Kodoc |
87
|
|
|
$this->kodoc = new Kodoc($type, $file); |
88
|
|
|
|
89
|
|
|
// Set the title |
90
|
|
|
$this->template->title = implode('/', $this->uri->segment_array(1)); |
91
|
|
|
|
92
|
|
|
// Load documentation for this file |
93
|
|
|
$this->template->content = new View('kodoc/documentation'); |
94
|
|
|
|
95
|
|
|
// Exit this method |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
// Nothing to document |
101
|
|
|
url::redirect('kodoc'); |
102
|
|
|
} |
103
|
|
|
} // End Kodoc Controller |
104
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: