Move src/ to app/
This commit is contained in:
113
app/helpers.php
Normal file
113
app/helpers.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Roots\Sage\Container;
|
||||
use Illuminate\Contracts\Container\Container as ContainerContract;
|
||||
|
||||
/**
|
||||
* Get the sage container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param array $parameters
|
||||
* @param ContainerContract $container
|
||||
* @return ContainerContract|mixed
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
function sage($abstract = null, $parameters = [], ContainerContract $container = null)
|
||||
{
|
||||
$container = $container ?: Container::getInstance();
|
||||
if (!$abstract) {
|
||||
return $container;
|
||||
}
|
||||
return $container->bound($abstract)
|
||||
? $container->make($abstract, $parameters)
|
||||
: $container->make("sage.{$abstract}", $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get / set the specified configuration value.
|
||||
*
|
||||
* If an array is passed as the key, we will assume you want to set an array of values.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param mixed $default
|
||||
* @return mixed|\Roots\Sage\Config
|
||||
* @copyright Taylor Otwell
|
||||
* @link https://github.com/laravel/framework/blob/c0970285/src/Illuminate/Foundation/helpers.php#L254-L265
|
||||
*/
|
||||
function config($key = null, $default = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return sage('config');
|
||||
}
|
||||
if (is_array($key)) {
|
||||
return sage('config')->set($key);
|
||||
}
|
||||
return sage('config')->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
function template($file, $data = [])
|
||||
{
|
||||
return sage('blade')->render($file, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve path to a compiled blade view
|
||||
* @param $file
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
function template_path($file, $data = [])
|
||||
{
|
||||
return sage('blade')->compiledPath($file, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $asset
|
||||
* @return string
|
||||
*/
|
||||
function asset_path($asset)
|
||||
{
|
||||
return sage('assets')->getUri($asset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether to show the sidebar
|
||||
* @return bool
|
||||
*/
|
||||
function display_sidebar()
|
||||
{
|
||||
static $display;
|
||||
isset($display) || $display = apply_filters('sage/display_sidebar', false);
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page titles
|
||||
* @return string
|
||||
*/
|
||||
function title()
|
||||
{
|
||||
if (is_home()) {
|
||||
if ($home = get_option('page_for_posts', true)) {
|
||||
return get_the_title($home);
|
||||
}
|
||||
return __('Latest Posts', 'sage');
|
||||
}
|
||||
if (is_archive()) {
|
||||
return get_the_archive_title();
|
||||
}
|
||||
if (is_search()) {
|
||||
return sprintf(__('Search Results for %s', 'sage'), get_search_query());
|
||||
}
|
||||
if (is_404()) {
|
||||
return __('Not Found', 'sage');
|
||||
}
|
||||
return get_the_title();
|
||||
}
|
||||
Reference in New Issue
Block a user