-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
117 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# editorconfig.org | ||
|
||
root = false | ||
|
||
[*.php] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php namespace Roots\Sage\Template; | ||
|
||
/** | ||
* Class Wrapper | ||
* @package Roots\Sage | ||
* @author QWp6t | ||
*/ | ||
class WrapperCollection { | ||
/** @var $this */ | ||
protected static $instance; | ||
/** @var WrapperInterface[] $wrappers */ | ||
protected $wrappers = []; | ||
|
||
/** Singleton */ | ||
private function __construct() {} | ||
private function __clone() {} | ||
|
||
/** | ||
* @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."); | ||
} | ||
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 string $slug | ||
* @return null|WrapperInterface | ||
*/ | ||
public static function get($slug) { | ||
return isset(self::instance()->wrappers[$slug]) ? self::instance()->wrappers[$slug] : null; | ||
} | ||
|
||
/** | ||
* @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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters