Skip to content

Commit

Permalink
chore: deprecate leaf view
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Aug 14, 2024
1 parent ec117bb commit 62ed301
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ public static function set($item, $value = null)
}
}

/**
* Attach view engine to Leaf view
*
* @param mixed $className The class to attach
* @param string|null $name The key to save view engine with
*/
public static function attachView($className, $name = null)
{
$class = new $className();
$diIndex = $name ?? static::getDiIndex($class);

static::set("views.$diIndex", $class);
}

/**
* Grab context
*
Expand Down Expand Up @@ -212,6 +226,14 @@ protected static function mapContext(string $item, $value = null)
)];
}

protected static function getDiIndex($class)
{
$fullName = \explode("\\", \strtolower(\get_class($class)));
$className = $fullName[\count($fullName) - 1];

return $className;
}

/**
* Property Overloading
*/
Expand Down
2 changes: 2 additions & 0 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* @author Michael Darko <mickdd22@gmail.com>
* @since v2.4.4
* @deprecated All functionality is now available through the Config class
*/
class View
{
Expand All @@ -21,6 +22,7 @@ class View
*
* @param mixed $className The class to attach
* @param string|null $name The key to save view engine with
* @deprecated use Config::attachView instead
*/
public static function attach($className, $name = null)
{
Expand Down

0 comments on commit 62ed301

Please sign in to comment.