Last active
August 29, 2015 14:16
-
-
Save vanchelo/e4cab3bf102fb8d1206b to your computer and use it in GitHub Desktop.
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
<?php | |
use Illuminate\Support\Facades\Facade; | |
class Title extends Facade | |
{ | |
protected static function getFacadeAccessor() | |
{ | |
return 'title'; | |
} | |
} |
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
<?php | |
class Title | |
{ | |
/** | |
* Array of values | |
* | |
* @var array | |
*/ | |
protected $values = []; | |
/** | |
* Values delimiter | |
* | |
* @var string | |
*/ | |
protected $delimiter; | |
/** | |
* Constructor | |
* | |
* @param $value | |
* @param string $delimiter | |
*/ | |
function __construct($value, $delimiter = ' :: ') | |
{ | |
$this->values[] = $value; | |
$this->delimiter = $delimiter; | |
} | |
/** | |
* Put value at the end | |
* | |
* @param string $value | |
* @param null $delimiter | |
*/ | |
public function append($value = '', $delimiter = null) | |
{ | |
$this->values[] = $delimiter ?: $this->delimiter; | |
$this->values[] = $value; | |
} | |
/** | |
* Put value at the start | |
* | |
* @param string $value | |
* @param null $delimiter | |
*/ | |
public function prepend($value = '', $delimiter = null) | |
{ | |
array_unshift($this->values, $value, $delimiter ?: $this->delimiter); | |
} | |
/** | |
* Render title | |
* | |
* @return string | |
*/ | |
public function render() | |
{ | |
return implode('', $this->values); | |
} | |
/** | |
* Get last value | |
* | |
* @return mixed | |
*/ | |
public function last() | |
{ | |
return end($this->values); | |
} | |
/** | |
* Get first value | |
* | |
* @return mixed | |
*/ | |
public function first() | |
{ | |
return reset($this->values); | |
} | |
/** | |
* To string implementation | |
* | |
* @return string | |
*/ | |
function __toString() | |
{ | |
return $this->render(); | |
} | |
} |
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
<?php | |
use Illuminate\Support\ServiceProvider; | |
use Title; | |
class TitleServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register the service provider. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app->bindShared('title', function () | |
{ | |
return new Title( | |
$this->app['config']->get('app.site_name'), | |
$this->app['config']->get('app.title_delimiter') | |
); | |
}); | |
$this->app->singleton('Shop\Commons\Helpers\Title', 'title'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment