Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-view
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-view
Merge requests
!4
view builder
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
view builder
feature/builder
into
master
Overview
0
Commits
1
Pipelines
1
Changes
6
Merged
Krzysztof Dyszczyk
requested to merge
feature/builder
into
master
5 years ago
Overview
0
Commits
1
Pipelines
1
Changes
6
Expand
👍
0
👎
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
f88dfe61
1 commit,
5 years ago
6 files
+
120
−
1
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
src/PluginViewBuilder.php
0 → 100644
+
70
−
0
Options
<?php
namespace
WPDesk\View
;
use
WPDesk\View\Renderer\SimplePhpRenderer
;
use
WPDesk\View\Resolver\ChainResolver
;
use
WPDesk\View\Resolver\DirResolver
;
use
WPDesk\View\Resolver\WPThemeResolver
;
/**
* Facilitates building of the default plugin renderer.
*
* @package WPDesk\View
*/
class
PluginViewBuilder
{
/** @var string */
private
$plugin_dir
;
/** @var string[] */
private
$template_dirs
;
/**
* @param string $plugin_dir Plugin directory path(absolute path)
* @param string|string[] $template_dir Directory or list of directories with templates to render
*/
public
function
__construct
(
$plugin_dir
,
$template_dir
=
'templates'
)
{
$this
->
plugin_dir
=
$plugin_dir
;
if
(
!
is_array
(
$template_dir
)
)
{
$this
->
template_dirs
=
[
$template_dir
];
}
else
{
$this
->
template_dirs
=
$template_dir
;
}
}
/**
* Creates simple renderer that search for the templates in plugin dir and in theme/child dir.
*
* For example if your plugin dir is /plugin, template dir is /templates, theme is /theme, and a child theme is /child
* the templates will be loaded from(order is important):
* - /child/plugin/*.php
* - /theme/plugin/*.php
* - /plugin/templates/*.php
*
* @return SimplePhpRenderer
*/
public
function
createSimpleRenderer
()
{
$resolver
=
new
ChainResolver
();
$resolver
->
appendResolver
(
new
WPThemeResolver
(
basename
(
$this
->
plugin_dir
)
)
);
foreach
(
$this
->
template_dirs
as
$dir
)
{
$dir
=
trailingslashit
(
$this
->
plugin_dir
)
.
trailingslashit
(
$dir
);
$resolver
->
appendResolver
(
new
DirResolver
(
$dir
)
);
}
return
new
SimplePhpRenderer
(
$resolver
);
}
/**
* Load templates using simple renderer.
*
* @param string $name Name of the template
* @param string $path Additional path of the template ie. for path "path" the templates would be loaded from /plugin/templates/path/*.php
* @param array $args Arguments for templates to use
*
* @return string Rendered template.
*/
public
function
loadTemplate
(
$name
,
$path
=
'.'
,
$args
=
array
()
)
{
$renderer
=
$this
->
createSimpleRenderer
();
return
$renderer
->
render
(
trailingslashit
(
$path
)
.
$name
,
$args
);
}
}
\ No newline at end of file
Loading