forked from TerrePorter/StringBladeCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringView.php
More file actions
141 lines (121 loc) · 3.96 KB
/
Copy pathStringView.php
File metadata and controls
141 lines (121 loc) · 3.96 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Wpb\String_Blade_Compiler;
use App, ArrayAccess;
use Config;
use Illuminate\View\Engines\EngineInterface;
use Illuminate\Contracts\View\View as ViewContract;
class StringView extends View implements ArrayAccess, ViewContract {
protected $template_field = 'template';
/**
* Create a new view instance.
*
* @param \Wpb\String_Blade_Compiler\Factory $factory
* @param \Illuminate\View\Engines\EngineInterface $engine
* @param string $view
* @param string $path
* @param array $data
*
*/
public function __construct(Factory $factory, EngineInterface $engine, $view, $path, $data = [])
{
// setup variables
$this->view = (is_array($view))?(object) $view:$view;
$this->path = $this->view;
$this->engine = $engine;
$this->factory = $factory;
$this->data = $this->parseData($data);
//$this->data = $data instanceof Arrayable ? $data->toArray() : (array) $data;
// if ($data instanceof Arrayable) {
// var_dump($this->data);
//}
// check if view has secondsTemplateCacheExpires set, or get from config
if ( !property_exists($this->view, "secondsTemplateCacheExpires") || !is_numeric($this->view->secondsTemplateCacheExpires) ) {
$this->view->secondsTemplateCacheExpires = config('blade.secondsTemplateCacheExpires');
if ( is_null($this->view->secondsTemplateCacheExpires) ) {
$this->view->secondsTemplateCacheExpires = 0;
}
}
// this is the actually blade template data
if ( !property_exists($this->view, "template") )
{
// is the same as sending a blank template file
$this->view->template = '';
}
// each template requires a unique cache key, or generate one
if ( !property_exists($this->view, "cache_key") )
{
// special, to catch if template is empty
if (empty($this->view->template)) {
$this->view->cache_key = md5('_empty_template_');
} else {
$this->view->cache_key = md5($this->view->template);
}
}
}
/**
* Get the name of the view.
*
* @return string
*/
public function getName()
{
return (isset($this->view->template)?md5($this->view->template):'StringViewTemplate');
}
/**
* Get a evaluated view contents for the given view.
*
* @param object $view
* @param array $data
* @param array $mergeData
* @return \Illuminate\View\View
* @throws \Exception
*/
public function make($view, $data = array(), $mergeData = array())
{
$this->path = $view;
$this->data = array_merge($mergeData, $this->parseData($data));
return $this;
}
/**
* Get the evaluated contents of the view.
*
* @return string
*/
protected function getContents()
{
/**
* This property will be added to models being compiled with StringView
* to keep track of which field in the model is being compiled
*/
$this->path->__string_blade_compiler_template_field = $this->template_field;
return $this->engine->get($this->path, $this->gatherData());
//return parent::getContents();
}
/**
* Parse the given data into a raw array.
*
* @param mixed $data
* @return array
*/
protected function parseData($data)
{
return $data instanceof Arrayable ? $data->toArray() : $data;
}
/**
* Checks if a string is a valid timestamp.
* from https://gist.github.com/sepehr/6351385
*
* @param string $timestamp Timestamp to validate.
*
* @return bool
*/
function is_timestamp($timestamp)
{
$check = (is_int($timestamp) OR is_float($timestamp))
? $timestamp
: (string) (int) $timestamp;
return ($check === $timestamp)
AND ( (int) $timestamp <= PHP_INT_MAX)
AND ( (int) $timestamp >= ~PHP_INT_MAX);
}
}