Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-view
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-view
Merge requests
!8
feat/woo template
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
feat/woo template
feat/woo-template
into
devel
Overview
0
Commits
26
Pipelines
1
Changes
6
Open
Bartek Jaskulski
requested to merge
feat/woo-template
into
devel
1 year ago
Overview
0
Commits
26
Pipelines
1
Changes
6
Common project files update
Common project files update
test suite init
theme resolver test
tests for wptheme resolver
implementation of wp theme resolver
tests for dir resolver
chain resolver tests
dir resolver implementation
better renderer interface
fixed chain resolver tests
chain resolver implementation
renderer tests
simple php renderer
remove php from resolvers. Only PHP renderer can add it
fix for invalid interface implementation
view builder
add output_render method
chore(readme): more documentation
chore(readme): more documentation
feat: add WooTemplateResolver
0
0
Merge request reports
Viewing commit
8aa5ae0b
Prev
Next
Show latest version
6 files
+
120
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
8aa5ae0b
Merge branch 'feature/builder' into 'master'
· 8aa5ae0b
Dyszczo
authored
5 years ago
view builder See merge request
!4
src/PluginViewBuilder.php
0 → 100644
+
70
−
0
View file @ 8aa5ae0b
Edit in single-file editor
Open in Web IDE
<?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