Conform to new rules
This commit is contained in:
@@ -5,55 +5,61 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
class Wrapper implements WrapperInterface {
|
||||
/** @var string Wrapper slug */
|
||||
protected $slug;
|
||||
class Wrapper implements WrapperInterface
|
||||
{
|
||||
/** @var string Wrapper slug */
|
||||
protected $slug;
|
||||
|
||||
/** @var string Template file that is being wrapped */
|
||||
protected $template = '';
|
||||
/** @var string Template file that is being wrapped */
|
||||
protected $template = '';
|
||||
|
||||
/** @var string[] Array of template wrappers; e.g., `base-singular.php`, `base-page.php`, `base.php` */
|
||||
protected $wrapper = [];
|
||||
/** @var string[] Array of template wrappers; e.g., `base-singular.php`, `base-page.php`, `base.php` */
|
||||
protected $wrapper = [];
|
||||
|
||||
/** @var string[] Cache template locations */
|
||||
protected static $locations = [];
|
||||
/** @var string[] Cache template locations */
|
||||
protected static $locations = [];
|
||||
|
||||
/**
|
||||
* Wrapper constructor
|
||||
*
|
||||
* @param string $template Template file, as from Template Heirarchy; e.g., `page.php`, `single.php`, `singular.php`
|
||||
* @param string $base Wrapper's base template, this is what will wrap around $template
|
||||
*/
|
||||
public function __construct($template, $base = 'layouts/base.php') {
|
||||
$this->slug = sanitize_title(basename($base, '.php'));
|
||||
$this->wrapper = [$base];
|
||||
$this->template = $template;
|
||||
$str = substr($base, 0, -4);
|
||||
array_unshift($this->wrapper, sprintf($str . '-%s.php', basename($template, '.php')));
|
||||
}
|
||||
/**
|
||||
* Wrapper constructor
|
||||
*
|
||||
* @param string $template Template file, as from Template Heirarchy; e.g., `page.php`, `single.php`, `singular.php`
|
||||
* @param string $base Wrapper's base template, this is what will wrap around $template
|
||||
*/
|
||||
public function __construct($template, $base = 'layouts/base.php')
|
||||
{
|
||||
$this->slug = sanitize_title(basename($base, '.php'));
|
||||
$this->wrapper = [$base];
|
||||
$this->template = $template;
|
||||
$str = substr($base, 0, -4);
|
||||
array_unshift($this->wrapper, sprintf($str . '-%s.php', basename($template, '.php')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @see getTemplate
|
||||
*/
|
||||
public function __toString() {
|
||||
return $this->getTemplate();
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
* @see getTemplate
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getTemplate();
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getWrapper() {
|
||||
$wrappers = apply_filters('sage/wrap_' . $this->slug, $this->wrapper) ?: $this->wrapper;
|
||||
return locate_template($wrappers);
|
||||
}
|
||||
/** {@inheritdoc} */
|
||||
public function getWrapper()
|
||||
{
|
||||
$wrappers = apply_filters('sage/wrap_' . $this->slug, $this->wrapper) ?: $this->wrapper;
|
||||
return locate_template($wrappers);
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getSlug() {
|
||||
return $this->slug;
|
||||
}
|
||||
/** {@inheritdoc} */
|
||||
public function getSlug()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/** {@inheritdoc} */
|
||||
public function getTemplate() {
|
||||
$template = apply_filters('sage/unwrap_' . $this->slug, $this->template) ?: $this->template;
|
||||
return locate_template($template);
|
||||
}
|
||||
/** {@inheritdoc} */
|
||||
public function getTemplate()
|
||||
{
|
||||
$template = apply_filters('sage/unwrap_' . $this->slug, $this->template) ?: $this->template;
|
||||
return locate_template($template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,69 +5,78 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
class WrapperCollection {
|
||||
/** @var $this */
|
||||
protected static $instance;
|
||||
/** @var WrapperInterface[] $wrappers */
|
||||
protected $wrappers = [];
|
||||
class WrapperCollection
|
||||
{
|
||||
/** @var $this */
|
||||
protected static $instance;
|
||||
/** @var WrapperInterface[] $wrappers */
|
||||
protected $wrappers = [];
|
||||
|
||||
/** Singleton */
|
||||
private function __construct() {}
|
||||
private function __clone() {}
|
||||
/** Singleton */
|
||||
// @codingStandardsIgnoreStart
|
||||
private function __construct() {}
|
||||
private function __clone() {}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function instance() {
|
||||
isset(self::$instance) || self::$instance = new static;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WrapperInterface $wrapper
|
||||
* @param string $slug
|
||||
* @param bool $overwriteIfExists
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function add(WrapperInterface $wrapper, $slug = '', $overwriteIfExists = false) {
|
||||
$slug = $slug ?: $wrapper->getSlug();
|
||||
if (self::instance()->exists($slug) && !$overwriteIfExists) {
|
||||
throw new \Exception("Wrapper $slug already exists.");
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function instance()
|
||||
{
|
||||
isset(self::$instance) || self::$instance = new static;
|
||||
return self::$instance;
|
||||
}
|
||||
self::instance()->wrappers[$slug] = $wrapper;
|
||||
return self::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return $this
|
||||
*/
|
||||
public static function remove($slug) {
|
||||
unset(self::instance()->wrappers[$slug]);
|
||||
return self::instance();
|
||||
}
|
||||
/**
|
||||
* @param WrapperInterface $wrapper
|
||||
* @param string $slug
|
||||
* @param bool $overwriteIfExists
|
||||
* @return $this
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function add(WrapperInterface $wrapper, $slug = '', $overwriteIfExists = false)
|
||||
{
|
||||
$slug = $slug ?: $wrapper->getSlug();
|
||||
if (self::instance()->exists($slug) && !$overwriteIfExists) {
|
||||
throw new \Exception("Wrapper $slug already exists.");
|
||||
}
|
||||
self::instance()->wrappers[$slug] = $wrapper;
|
||||
return self::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return null|WrapperInterface
|
||||
*/
|
||||
public static function get($slug) {
|
||||
return isset(self::instance()->wrappers[$slug]) ? self::instance()->wrappers[$slug] : null;
|
||||
}
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return $this
|
||||
*/
|
||||
public static function remove($slug)
|
||||
{
|
||||
unset(self::instance()->wrappers[$slug]);
|
||||
return self::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Slugs of wrappers in collection
|
||||
*/
|
||||
public static function wrappers() {
|
||||
return array_keys(self::instance()->wrappers);
|
||||
}
|
||||
/**
|
||||
* @param string $slug
|
||||
* @return null|WrapperInterface
|
||||
*/
|
||||
public static function get($slug)
|
||||
{
|
||||
return isset(self::instance()->wrappers[$slug]) ? self::instance()->wrappers[$slug] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $slug
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($slug) {
|
||||
return isset(self::instance()->wrappers[$slug]);
|
||||
}
|
||||
/**
|
||||
* @return string[] Slugs of wrappers in collection
|
||||
*/
|
||||
public static function wrappers()
|
||||
{
|
||||
return array_keys(self::instance()->wrappers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $slug
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($slug)
|
||||
{
|
||||
return isset(self::instance()->wrappers[$slug]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,23 @@
|
||||
* @package Roots\Sage
|
||||
* @author QWp6t
|
||||
*/
|
||||
interface WrapperInterface {
|
||||
interface WrapperInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Get wrapper template file
|
||||
*
|
||||
* @return string Wrapper template (FQPN of, e.g., `base-page.php`, `base.php`)
|
||||
*/
|
||||
public function getWrapper();
|
||||
/**
|
||||
* Get wrapper template file
|
||||
*
|
||||
* @return string Wrapper template (FQPN of, e.g., `base-page.php`, `base.php`)
|
||||
*/
|
||||
public function getWrapper();
|
||||
|
||||
/**
|
||||
* @return string Wrapped template (FQPN of, e.g., `page.php`, `single.php`, `singular.php`)
|
||||
*/
|
||||
public function getTemplate();
|
||||
/**
|
||||
* @return string Wrapped template (FQPN of, e.g., `page.php`, `single.php`, `singular.php`)
|
||||
*/
|
||||
public function getTemplate();
|
||||
|
||||
/**
|
||||
* @return string Slug of the WrapperInterface; e.g., `base`
|
||||
*/
|
||||
public function getSlug();
|
||||
/**
|
||||
* @return string Slug of the WrapperInterface; e.g., `base`
|
||||
*/
|
||||
public function getSlug();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user