-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoute.php
More file actions
56 lines (43 loc) · 1.07 KB
/
Route.php
File metadata and controls
56 lines (43 loc) · 1.07 KB
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
<?php
require_once 'RouteMethod.php';
class Route
{
/**
* @var null
*/
private static $instance = null;
/**
* It Creates object of RouteMethod class at once and uses it ( Singleton Pattern )
* @param $arguments
* @return RouteMethodInterface
*/
public static function getRouteMethodInstance( $arguments ) : RouteMethodInterface
{
if ( self::$instance === null )
{
self::$instance = new RouteMethod( $arguments[0], $arguments[1] );
}
else{
self::$instance->setRouteString($arguments[0]);
self::$instance->setCallback($arguments[1]);
}
return self::$instance;
}
/**
* By CallStatic method every public methods from the RouteMethod class will be invoked statically
* @param string $name
* @param array $arguments
* @return mixed
*/
public static function __callStatic( string $name, array $arguments )
{
try{
$routeMethods = self::getRouteMethodInstance($arguments );
}
catch (Throwable $exception)
{
echo $exception->getMessage();
}
return call_user_func_array( [$routeMethods, $name], $arguments );
}
}