Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony committed Feb 25, 2016
0 parents commit f05ac03
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Tony/Themes/FileViewFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Tony\Themes;

use Illuminate\View\FileViewFinder as IlluminateViewFinder;

class FileViewFinder extends IlluminateViewFinder
{
/**
* This overrides the parent method and adds the location to the
* beginning of the paths array vs the end.
*
* @param string $location
* @return void
*/
public function addLocation($location)
{
//add location to the top of paths
array_unshift($this->paths, $location);
}

/**
* Allows us to remove view paths
*
* @param $location
* @return void
*/
public function removeLocation($location)
{
//find and remove location if set
if($key = array_search($location, $this->paths)) {
unset($this->paths[$key]);
}
}
}
24 changes: 24 additions & 0 deletions src/Tony/Themes/Theme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php namespace Tony\Themes;


class Theme
{
protected $theme = "";

/**
* Set the Theme
*
* @param $name
* @param null $absolute_path
*/
public function set($name, $absolute_path = null)
{
// Use default /larathemes/ directory if other is not set
if(empty($absolute_path)) $absolute_path = base_path('larathemes/'.$name);
// remove any other theme that was previously set
if(!empty($this->theme)) app('view.finder')->removeLocation($this->theme.'/views');
//set theme and add location to view file finder
if(is_dir($absolute_path)) $this->theme = $absolute_path;
app('view.finder')->addLocation($absolute_path.'/views');
}
}
23 changes: 23 additions & 0 deletions src/Tony/Themes/ThemeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php namespace Tony\Themes;

use View;
use Illuminate\Support\ServiceProvider;

class ThemeServiceProvider extends ServiceProvider
{

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['view.finder'] = $this->app->share(function($app) {
$paths = View::getFinder()->getPaths();
return new FileViewFinder($app['files'], $paths);
});
View::setFinder(app('view.finder'));
$this->app->bind('tony.larathemes', 'Tony\Themes\Theme');
}
}
27 changes: 27 additions & 0 deletions src/Tony/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "codewithtony/larathemes",
"description": "Theme Manager for Laravel 5",
"keywords": [ "Laravel 5", "Themes", "Laravel Theme", "Theme Manager" ],
"homepage": "https://github.com/codewithtony/larathemes",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Tony.",
"email": "tony@codewithtony.com",
"homepage": "http://www.codewithtony.com"
}
],
"support": {
"issues": "https://github.com/codewithtony/larathemes/issues"
},
"require": {
"php": ">=5.4.0",
"laravel/framework": "5.*"
},
"autoload": {
"psr-4": {
"Tony\\Themes\\": "src/Tony/Themes/"
}
}
}

0 comments on commit f05ac03

Please sign in to comment.