Controller_Core::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 2
b 1
f 0
nc 1
nop 2
dl 0
loc 5
rs 9.4285
1
<?php defined('SYSPATH') or die('No direct access allowed.');
2
/**
3
 * Kohana Controller class. The controller class must be extended to work
4
 * properly, so this class is defined as abstract.
5
 *
6
 * $Id: Controller.php 4365 2009-05-27 21:09:27Z samsoir $
7
 *
8
 * @package    Core
9
 * @author     Kohana Team
10
 * @copyright  (c) 2007-2008 Kohana Team
11
 * @license    http://kohanaphp.com/license.html
12
 */
13
abstract class Controller_Core
14
{
15
16
    // Allow all controllers to run in production by default
17
    const ALLOW_PRODUCTION = true;
18
19
    /**
20
     * Loads URI, and Input into this controller.
21
     *
22
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
23
     */
24
    public function __construct()
25
    {
26
        if (Kohana::$instance == null) {
27
            // Set the instance to the first controller loaded
28
            Kohana::$instance = $this;
29
        }
30
31
        // URI should always be available
32
        $this->uri = URI::instance();
0 ignored issues
show
Bug introduced by
The property uri does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
34
        // Input should always be available
35
        $this->input = Input::instance();
0 ignored issues
show
Bug introduced by
The property input does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
    }
37
38
    /**
39
     * Handles methods that do not exist.
40
     *
41
     * @param   string  method name
42
     * @param   array   arguments
43
     * @return  void
44
     */
45
    public function __call($method, $args)
46
    {
47
        // Default to showing a 404 page
48
        Event::run('system.404');
49
    }
50
51
    /**
52
     * Includes a View within the controller scope.
53
     *
54
     * @param   string  view filename
55
     * @param   array   array of view variables
56
     * @return  string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
57
     */
58
    public function _kohana_load_view($kohana_view_filename, $kohana_input_data)
59
    {
60
        if ($kohana_view_filename == '') {
61
            return;
62
        }
63
64
        // Buffering on
65
        ob_start();
66
67
        // Import the view variables to local namespace
68
        extract($kohana_input_data, EXTR_SKIP);
69
70
        // Views are straight HTML pages with embedded PHP, so importing them
71
        // this way insures that $this can be accessed as if the user was in
72
        // the controller, which gives the easiest access to libraries in views
73
        try {
74
            include $kohana_view_filename;
75
        } catch (Exception $e) {
76
            ob_end_clean();
77
            throw $e;
78
        }
79
80
        // Fetch the output and close the buffer
81
        return ob_get_clean();
82
    }
83
} // End Controller Class
84