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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<?php
namespace app\controllers;
use \Benchmark;
/** Resolve class
* will resolve ambiguous utl-request patterns
* ---
* Then it can route the request to some controller;
* Alternatively it can proccess the request via Models
* and initiate the View engine
*/
class Resolve {
public static function url($array)
{
$fullUrl = implode('/', $array);
$url = $array[count($array) - 1];
if (!PRODUCTION) Benchmark::add_spot('proxy-page');
// proxying check if page with this url
$page = proxy(
[\app\models\cms\Page_model::class, 'fromUrl'],
[ $fullUrl ], CACHE_ROOT_TTL,
PROXY_CACHE_ERRORS
);
// if page exist, construct page
if ($page !== false) {
// page exists, render page
load_template('base', [ 'page' => [
'title' => $page['Title'],
'seo' => [],
'sections' => [
[
'view' => 'content/static',
'key' => 'page',
'data' => $page
]
]
]
]);
return ;
}
if (!PRODUCTION) Benchmark::add_spot('proxy-category');
// proxying check if products category with this url
$category = proxy(
[\app\models\market\ProductCategories_model::class, 'categoryFromUrl'],
[ $fullUrl ], CACHE_CATEGORY_TTL
);
// if category exist, construct category
if ($category !== false) {
// render page
load_template('products', [ 'data' => [
'title' => $category['Title'],
'seo' => [],
'tree' => proxy(
[\app\models\market\ProductCategories_model::class, 'tree'],
[], CACHE_ROOT_TTL
),
'hierarchyPath' => explode('.', substr($category['Hierarchy'], 1, -1)),
'sections' => [
[
'view' => 'content/product_list/Product_List_Filters',
'key' => 'filters',
'data' => $category
],
[
'view' => 'content/product_list/product_list',
'key' => 'products',
'data' => $category['products']
]
]
]
]);
return ;
}
// not page nor category?: reply 404
header("HTTP/1.0 404 Not Found");
render_view('error/404', ['message' => 'Say something I\'m givin\' up on you.']);
}
}
|