22
33namespace Scriptor \Core ;
44
5+ use Imanager \Input ;
56use Imanager \Item ;
7+ use Imanager \SectionCache ;
68use Imanager \TemplateParser ;
9+ use Imanager \UrlSegments ;
710use Imanager \Util ;
11+ use Scriptor \Core \Modules \Parsedown ;
812
913class Site extends Module
1014{
@@ -93,11 +97,6 @@ class Site extends Module
9397 */
9498 public $ version ;
9599
96- /**
97- * @var object - ParseDown instance
98- */
99- public $ parsedown ;
100-
101100 /**
102101 * @var object - ItemManager's TemplateParser instance
103102 */
@@ -124,11 +123,10 @@ public function init()
124123 parent ::init ();
125124 $ this ->templateParser = new TemplateParser ();
126125 $ this ->themeUrl = $ this ->siteUrl .'/site/themes/ ' .$ this ->config ['theme_path ' ];
127- $ this ->input = $ this ->input ();//imanager->input;
126+ $ this ->input = $ this ->input ();
128127 $ this ->urlSegments = $ this ->urlSegments ();
129- $ this ->firstSegment = $ this ->urlSegments ->get (0 );
130- $ this ->lastSegment = $ this ->urlSegments ->getLast ();
131- $ this ->parsedown = $ this ->loadModule ('parsedown ' , ['namespace ' => __NAMESPACE__ .'\Modules \\' ]);
128+ $ this ->firstSegment = $ this ->urlSegments ->get (0 ); // Kick it out
129+ $ this ->lastSegment = $ this ->urlSegments ->getLast (); // same here
132130 $ this ->version = Scriptor::VERSION ;
133131 }
134132
@@ -164,34 +162,59 @@ public function execute() :void
164162 }
165163 }
166164
167- public function input ()
165+ public function input () : Input
168166 {
169167 return ($ this ->input ) ?? $ this ->imanager ->input ;
170168 }
171169
172- public function urlSegments ()
170+ public function urlSegments () : UrlSegments
173171 {
174172 return ($ this ->urlSegments ) ?? $ this ->input ->urlSegments ;
175173 }
176174
177- public function pages ()
175+ public function sectionCache () : SectionCache
176+ {
177+ return $ this ->imanager ->sectionCache ;
178+ }
179+
180+ public function pages () : Pages
178181 {
179182 return ($ this ->pages ) ?? new Pages ();
180183 }
181184
182- public function users ()
185+ public function users () : Users
183186 {
184187 return ($ this ->users ) ?? new Users ();
185188 }
186189
190+ public function parsedown () : Parsedown
191+ {
192+ if (!isset ($ this ->parsedown )) {
193+ $ this ->parsedown = $ this ->loadModule ('parsedown ' , ['namespace ' => __NAMESPACE__ .'\Modules \\' ]);
194+ }
195+ return $ this ->parsedown ;
196+ }
197+
187198 /**
188- * NOTE: "segment " is used only for compatibility reasons.
199+ * NOTE: "segments " is used only for compatibility reasons.
189200 */
190201 public function __get ($ arg )
191202 {
192- if ($ arg == 'pages ' ) return $ this ->pages ();
193- elseif ($ arg == 'segments ' || $ arg == 'urlSegments ' ) return $ this ->urlSegments ();
194- elseif ($ arg == 'users ' ) return $ this ->users ();
203+ switch ($ arg ) {
204+ case 'pages ' :
205+ return $ this ->pages ();
206+ break ;
207+ case 'segments ' :
208+ case 'urlSegments ' :
209+ return $ this ->urlSegments ();
210+ break ;
211+ case 'users ' :
212+ return $ this ->users ();
213+ break ;
214+ case 'parsedown ' :
215+ return $ this ->parsedown ();
216+ break ;
217+ }
195218 }
196219
197220 public static function getPageUrl ($ item , $ pages )
0 commit comments