From 1a8dce9b092e8bbe1d1921c43eb3691f3399b0a7 Mon Sep 17 00:00:00 2001 From: Date: Sun, 9 Jul 2017 07:05:07 -0700 Subject: [PATCH] Use roots/sage-lib (incl. new config system) --- app/filters.php | 28 +- app/helpers.php | 42 +- app/lib/Sage/Assets/JsonManifest.php | 41 -- app/lib/Sage/Assets/ManifestInterface.php | 31 - app/lib/Sage/Config.php | 8 - app/lib/Sage/Container.php | 10 - app/lib/Sage/Template/Blade.php | 129 ---- app/lib/Sage/Template/BladeProvider.php | 91 --- app/lib/Sage/Template/FileViewFinder.php | 40 -- app/setup.php | 37 +- composer.json | 14 +- composer.lock | 813 ++++++++++++---------- config/assets.php | 31 + config/theme.php | 32 + config/view.php | 51 ++ resources/functions.php | 34 +- 16 files changed, 626 insertions(+), 806 deletions(-) delete mode 100644 app/lib/Sage/Assets/JsonManifest.php delete mode 100644 app/lib/Sage/Assets/ManifestInterface.php delete mode 100644 app/lib/Sage/Config.php delete mode 100644 app/lib/Sage/Container.php delete mode 100644 app/lib/Sage/Template/Blade.php delete mode 100644 app/lib/Sage/Template/BladeProvider.php delete mode 100644 app/lib/Sage/Template/FileViewFinder.php create mode 100644 config/assets.php create mode 100644 config/theme.php create mode 100644 config/view.php diff --git a/app/filters.php b/app/filters.php index 050bf8f..9969266 100644 --- a/app/filters.php +++ b/app/filters.php @@ -40,16 +40,7 @@ collect([ 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date', 'home', 'frontpage', 'page', 'paged', 'search', 'single', 'singular', 'attachment' ])->map(function ($type) { - add_filter("{$type}_template_hierarchy", function ($templates) { - return collect($templates)->flatMap(function ($template) { - $transforms = [ - '%^/?(resources[\\/]views)?[\\/]?%' => '', - '%(\.blade)?(\.php)?$%' => '' - ]; - $normalizedTemplate = preg_replace(array_keys($transforms), array_values($transforms), $template); - return ["{$normalizedTemplate}.blade.php", "{$normalizedTemplate}.php"]; - })->toArray(); - }); + add_filter("{$type}_template_hierarchy", __NAMESPACE__.'\\filter_templates'); }); /** @@ -59,12 +50,21 @@ add_filter('template_include', function ($template) { $data = collect(get_body_class())->reduce(function ($data, $class) use ($template) { return apply_filters("sage/template/{$class}/data", $data, $template); }, []); - echo template($template, $data); - // Return a blank file to make WordPress happy - return get_theme_file_path('index.php'); + if ($template) { + echo template($template, $data); + return get_stylesheet_directory().'/index.php'; + } + return $template; }, PHP_INT_MAX); /** * Tell WordPress how to find the compiled path of comments.blade.php */ -add_filter('comments_template', 'App\\template_path'); +add_filter('comments_template', function ($comments_template) { + $comments_template = str_replace( + [get_stylesheet_directory(), get_template_directory()], + '', + $comments_template + ); + return template_path(locate_template(["views/{$comments_template}", $comments_template]) ?: $comments_template); +}); diff --git a/app/helpers.php b/app/helpers.php index b56c162..f3726bb 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -3,16 +3,14 @@ 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) + * @param Container $container + * @return Container|mixed */ function sage($abstract = null, $parameters = [], ContainerContract $container = null) { @@ -77,6 +75,42 @@ function asset_path($asset) return sage('assets')->getUri($asset); } +/** + * @param string|string[] $templates Possible template files + * @return array + */ +function filter_templates($templates) +{ + return collect($templates) + ->map(function ($template) { + return preg_replace('#\.(blade\.)?php$#', '', ltrim($template)); + }) + ->flatMap(function ($template) { + $paths = apply_filters('sage/filter_templates/paths', ['views', 'resources/views']); + return collect($paths) + ->flatMap(function ($path) use ($template) { + return [ + "{$path}/{$template}.blade.php", + "{$path}/{$template}.php", + "{$template}.blade.php", + "{$template}.php", + ]; + }); + }) + ->filter() + ->unique() + ->all(); +} + +/** + * @param string|string[] $templates Relative path to possible template files + * @return string Location of the template + */ +function locate_template($templates) +{ + return \locate_template(filter_templates($templates)); +} + /** * Determine whether to show the sidebar * @return bool diff --git a/app/lib/Sage/Assets/JsonManifest.php b/app/lib/Sage/Assets/JsonManifest.php deleted file mode 100644 index 37e5839..0000000 --- a/app/lib/Sage/Assets/JsonManifest.php +++ /dev/null @@ -1,41 +0,0 @@ -manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : []; - $this->dist = $distUri; - } - - /** @inheritdoc */ - public function get($asset) - { - return isset($this->manifest[$asset]) ? $this->manifest[$asset] : $asset; - } - - /** @inheritdoc */ - public function getUri($asset) - { - return "{$this->dist}/{$this->get($asset)}"; - } -} diff --git a/app/lib/Sage/Assets/ManifestInterface.php b/app/lib/Sage/Assets/ManifestInterface.php deleted file mode 100644 index a1542ee..0000000 --- a/app/lib/Sage/Assets/ManifestInterface.php +++ /dev/null @@ -1,31 +0,0 @@ -env = $env; - $this->app = $app; - } - - /** - * Get the compiler - * - * @return \Illuminate\View\Compilers\BladeCompiler - */ - public function compiler() - { - static $engineResolver; - if (!$engineResolver) { - $engineResolver = $this->app->make('view.engine.resolver'); - } - return $engineResolver->resolve('blade')->getCompiler(); - } - - /** - * @param string $view - * @param array $data - * @param array $mergeData - * @return string - */ - public function render($view, $data = [], $mergeData = []) - { - /** @var \Illuminate\Contracts\Filesystem\Filesystem $filesystem */ - $filesystem = $this->app['files']; - return $this->{$filesystem->exists($view) ? 'file' : 'make'}($view, $data, $mergeData)->render(); - } - - /** - * @param string $file - * @param array $data - * @param array $mergeData - * @return string - */ - public function compiledPath($file, $data = [], $mergeData = []) - { - $rendered = $this->file($file, $data, $mergeData); - /** @var EngineInterface $engine */ - $engine = $rendered->getEngine(); - - if (!($engine instanceof CompilerEngine)) { - // Using PhpEngine, so just return the file - return $file; - } - - $compiler = $engine->getCompiler(); - $compiledPath = $compiler->getCompiledPath($rendered->getPath()); - if ($compiler->isExpired($compiledPath)) { - $compiler->compile($file); - } - return $compiledPath; - } - - /** - * @param string $file - * @return string - */ - public function normalizeViewPath($file) - { - // Convert `\` to `/` - $view = str_replace('\\', '/', $file); - - // Add namespace to path if necessary - $view = $this->applyNamespaceToPath($view); - - // Remove unnecessary parts of the path - $view = str_replace(array_merge($this->app['config']['view.paths'], ['.blade.php', '.php']), '', $view); - - // Remove superfluous and leading slashes - return ltrim(preg_replace('%//+%', '/', $view), '/'); - } - - /** - * Convert path to view namespace - * @param string $path - * @return string - */ - public function applyNamespaceToPath($path) - { - /** @var ViewFinderInterface $finder */ - $finder = $this->app['view.finder']; - if (!method_exists($finder, 'getHints')) { - return $path; - } - $delimiter = $finder::HINT_PATH_DELIMITER; - $hints = $finder->getHints(); - $view = array_reduce(array_keys($hints), function ($view, $namespace) use ($delimiter, $hints) { - return str_replace($hints[$namespace], $namespace.$delimiter, $view); - }, $path); - return preg_replace("%{$delimiter}[\\/]*%", $delimiter, $view); - } - - /** - * Pass any method to the view Factory instance. - * - * @param string $method - * @param array $params - * @return mixed - */ - public function __call($method, $params) - { - return call_user_func_array([$this->env, $method], $params); - } -} diff --git a/app/lib/Sage/Template/BladeProvider.php b/app/lib/Sage/Template/BladeProvider.php deleted file mode 100644 index 63f3247..0000000 --- a/app/lib/Sage/Template/BladeProvider.php +++ /dev/null @@ -1,91 +0,0 @@ -app->bindIf('config', function () use ($config) { - return $config; - }, true); - } - - /** - * Bind required instances for the service provider. - */ - public function register() - { - $this->registerFilesystem(); - $this->registerEvents(); - $this->registerEngineResolver(); - $this->registerViewFinder(); - $this->registerFactory(); - return $this; - } - - /** - * Register Filesystem - */ - public function registerFilesystem() - { - $this->app->bindIf('files', Filesystem::class, true); - return $this; - } - - /** - * Register the events dispatcher - */ - public function registerEvents() - { - $this->app->bindIf('events', Dispatcher::class, true); - return $this; - } - - /** @inheritdoc */ - public function registerEngineResolver() - { - parent::registerEngineResolver(); - return $this; - } - - /** @inheritdoc */ - public function registerFactory() - { - parent::registerFactory(); - return $this; - } - - /** - * Register the view finder implementation. - */ - public function registerViewFinder() - { - $this->app->bindIf('view.finder', function ($app) { - $config = $this->app['config']; - $paths = $config['view.paths']; - $namespaces = $config['view.namespaces']; - $finder = new FileViewFinder($app['files'], $paths); - array_map([$finder, 'addNamespace'], array_keys($namespaces), $namespaces); - return $finder; - }, true); - return $this; - } -} diff --git a/app/lib/Sage/Template/FileViewFinder.php b/app/lib/Sage/Template/FileViewFinder.php deleted file mode 100644 index daadce7..0000000 --- a/app/lib/Sage/Template/FileViewFinder.php +++ /dev/null @@ -1,40 +0,0 @@ - $part) { - $templates[] = $templates[$i].self::FALLBACK_PARTS_DELIMITER.$part; - } - rsort($templates); - return $this->getPossibleViewFilesFromTemplates($templates); - } - - /** - * Get an array of possible view files from an array of templates - * - * @param array $templates - * @return array - */ - public function getPossibleViewFilesFromTemplates($templates) - { - return call_user_func_array('array_merge', array_map(function ($template) { - return array_map(function ($extension) use ($template) { - return str_replace('.', '/', $template).'.'.$extension; - }, $this->extensions); - }, $templates)); - } -} diff --git a/app/setup.php b/app/setup.php index 3c92a04..a6e6094 100644 --- a/app/setup.php +++ b/app/setup.php @@ -2,9 +2,8 @@ namespace App; -use Illuminate\Contracts\Container\Container as ContainerContract; +use Roots\Sage\Container; use Roots\Sage\Assets\JsonManifest; -use Roots\Sage\Config; use Roots\Sage\Template\Blade; use Roots\Sage\Template\BladeProvider; @@ -101,29 +100,6 @@ add_action('the_post', function ($post) { * Setup Sage options */ add_action('after_setup_theme', function () { - /** - * Sage config - */ - $paths = [ - 'dir.stylesheet' => get_stylesheet_directory(), - 'dir.template' => get_template_directory(), - 'dir.upload' => wp_upload_dir()['basedir'], - 'uri.stylesheet' => get_stylesheet_directory_uri(), - 'uri.template' => get_template_directory_uri(), - ]; - $viewPaths = collect(preg_replace('%[\/]?(resources/views)?[\/.]*?$%', '', [STYLESHEETPATH, TEMPLATEPATH])) - ->flatMap(function ($path) { - return ["{$path}/resources/views", $path]; - })->unique()->toArray(); - - config([ - 'assets.manifest' => "{$paths['dir.stylesheet']}/../dist/assets.json", - 'assets.uri' => "{$paths['uri.stylesheet']}/dist", - 'view.compiled' => "{$paths['dir.upload']}/cache/compiled", - 'view.namespaces' => ['App' => WP_CONTENT_DIR], - 'view.paths' => $viewPaths, - ] + $paths); - /** * Add JsonManifest to Sage container */ @@ -134,24 +110,19 @@ add_action('after_setup_theme', function () { /** * Add Blade to Sage container */ - sage()->singleton('sage.blade', function (ContainerContract $app) { + sage()->singleton('sage.blade', function (Container $app) { $cachePath = config('view.compiled'); if (!file_exists($cachePath)) { wp_mkdir_p($cachePath); } (new BladeProvider($app))->register(); - return new Blade($app['view'], $app); + return new Blade($app['view']); }); /** * Create @asset() Blade directive */ sage('blade')->compiler()->directive('asset', function ($asset) { - return ""; + return ""; }); }); - -/** - * Init config - */ -sage()->bindIf('config', Config::class, true); diff --git a/composer.json b/composer.json index 2c211da..ae6dca7 100644 --- a/composer.json +++ b/composer.json @@ -25,26 +25,26 @@ }, "autoload": { "psr-4": { - "Roots\\Sage\\": "app/lib/Sage/" + "App\\": "app/" } }, "require": { "php": ">=5.6.4", "composer/installers": "~1.0", - "illuminate/view": "~5.4", - "illuminate/config": "~5.4", - "soberwp/controller": "dev-master", - "roots/sage-installer": "~1.0" + "illuminate/support": "~5.4", + "roots/sage-lib": "~9.0.0-beta.3", + "soberwp/controller": "dev-master" }, "require-dev": { - "squizlabs/php_codesniffer": "^2.8.0" + "squizlabs/php_codesniffer": "^2.8.0", + "roots/sage-installer": "~1.1" }, "scripts": { "test": [ "phpcs" ], "post-create-project-cmd": [ - "Roots\\Sage\\Installer\\ComposerScript::postCreateProject" + "Roots\\Sage\\Installer\\ComposerScript::postCreateProject" ] } } diff --git a/composer.lock b/composer.lock index 6105407..96d236c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "fc2a3ea295ebcf82c9ed351b447446b2", + "content-hash": "9a56b0654d7dff65e2aebe6ed81833f3", "packages": [ { "name": "brain/hierarchy", @@ -344,57 +344,6 @@ "homepage": "https://laravel.com", "time": "2017-02-04T20:27:32+00:00" }, - { - "name": "illuminate/console", - "version": "v5.4.27", - "source": { - "type": "git", - "url": "https://github.com/illuminate/console.git", - "reference": "bdc5c6f53cb474e2aeec46b6a9999fcedfb62a4e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/illuminate/console/zipball/bdc5c6f53cb474e2aeec46b6a9999fcedfb62a4e", - "reference": "bdc5c6f53cb474e2aeec46b6a9999fcedfb62a4e", - "shasum": "" - }, - "require": { - "illuminate/contracts": "5.4.*", - "illuminate/support": "5.4.*", - "nesbot/carbon": "~1.20", - "php": ">=5.6.4", - "symfony/console": "~3.2" - }, - "suggest": { - "guzzlehttp/guzzle": "Required to use the ping methods on schedules (~6.0).", - "mtdowling/cron-expression": "Required to use scheduling component (~1.0).", - "symfony/process": "Required to use scheduling component (~3.2)." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.4-dev" - } - }, - "autoload": { - "psr-4": { - "Illuminate\\Console\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "The Illuminate Console package.", - "homepage": "https://laravel.com", - "time": "2017-06-10T13:11:18+00:00" - }, { "name": "illuminate/container", "version": "v5.4.27", @@ -680,59 +629,6 @@ "homepage": "https://laravel.com", "time": "2017-06-07T13:32:57+00:00" }, - { - "name": "nesbot/carbon", - "version": "1.22.1", - "source": { - "type": "git", - "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", - "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "symfony/translation": "~2.6 || ~3.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "~2", - "phpunit/phpunit": "~4.0 || ~5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.23-dev" - } - }, - "autoload": { - "psr-4": { - "Carbon\\": "src/Carbon/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Brian Nesbitt", - "email": "brian@nesbot.com", - "homepage": "http://nesbot.com" - } - ], - "description": "A simple API extension for DateTime.", - "homepage": "http://carbon.nesbot.com", - "keywords": [ - "date", - "datetime", - "time" - ], - "time": "2017-01-16T07:55:07+00:00" - }, { "name": "paragonie/random_compat", "version": "v2.0.10", @@ -829,34 +725,32 @@ "time": "2016-10-10T12:19:37+00:00" }, { - "name": "roots/sage-installer", - "version": "1.0.0", + "name": "roots/sage-lib", + "version": "9.0.0-beta.3", "source": { "type": "git", - "url": "https://github.com/roots/sage-installer.git", - "reference": "bd969d1a7c824ec7fe0579bf27181c9a729d8881" + "url": "https://github.com/roots/sage-lib.git", + "reference": "d7789609eae857e910812cf62ae55355b836ad58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/roots/sage-installer/zipball/bd969d1a7c824ec7fe0579bf27181c9a729d8881", - "reference": "bd969d1a7c824ec7fe0579bf27181c9a729d8881", + "url": "https://api.github.com/repos/roots/sage-lib/zipball/d7789609eae857e910812cf62ae55355b836ad58", + "reference": "d7789609eae857e910812cf62ae55355b836ad58", "shasum": "" }, "require": { - "illuminate/console": "~5.4", - "illuminate/filesystem": "~5.4", - "symfony/process": "~3.3" + "composer/installers": "~1.0", + "illuminate/config": "~5.4", + "illuminate/view": "~5.4", + "php": ">=5.6.4" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.0" + "squizlabs/php_codesniffer": "^2.8.0" }, - "bin": [ - "bin/sage" - ], "type": "library", "autoload": { "psr-4": { - "Roots\\Sage\\Installer\\": "src/" + "Roots\\Sage\\": "" } }, "notification-url": "https://packagist.org/downloads/", @@ -875,17 +769,12 @@ "homepage": "https://github.com/qwp6t" } ], - "description": "Sage installer.", + "description": "Library files for Sage Starter Theme", + "homepage": "https://roots.io/sage/", "keywords": [ - "FontAwesome", - "bootstrap", - "foundation", - "sage", - "tachyons", - "theme", "wordpress" ], - "time": "2017-07-01T22:49:02+00:00" + "time": "2017-07-09T11:48:17+00:00" }, { "name": "soberwp/controller", @@ -939,87 +828,18 @@ ], "time": "2017-06-25T13:13:49+00:00" }, - { - "name": "symfony/console", - "version": "v3.3.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "70d2a29b2911cbdc91a7e268046c395278238b2e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/70d2a29b2911cbdc91a7e268046c395278238b2e", - "reference": "70d2a29b2911cbdc91a7e268046c395278238b2e", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/debug": "~2.8|~3.0", - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "symfony/dependency-injection": "<3.3" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~3.3", - "symfony/dependency-injection": "~3.3", - "symfony/event-dispatcher": "~2.8|~3.0", - "symfony/filesystem": "~2.8|~3.0", - "symfony/http-kernel": "~2.8|~3.0", - "symfony/process": "~2.8|~3.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/filesystem": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Console Component", - "homepage": "https://symfony.com", - "time": "2017-06-02T19:24:58+00:00" - }, { "name": "symfony/debug", - "version": "v3.3.2", + "version": "v3.3.4", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "e9c50482841ef696e8fa1470d950a79c8921f45d" + "reference": "63b85a968486d95ff9542228dc2e4247f16f9743" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/e9c50482841ef696e8fa1470d950a79c8921f45d", - "reference": "e9c50482841ef696e8fa1470d950a79c8921f45d", + "url": "https://api.github.com/repos/symfony/debug/zipball/63b85a968486d95ff9542228dc2e4247f16f9743", + "reference": "63b85a968486d95ff9542228dc2e4247f16f9743", "shasum": "" }, "require": { @@ -1062,11 +882,11 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2017-06-01T21:01:25+00:00" + "time": "2017-07-05T13:02:37+00:00" }, { "name": "symfony/finder", - "version": "v3.3.2", + "version": "v3.3.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -1113,191 +933,18 @@ "homepage": "https://symfony.com", "time": "2017-06-01T21:01:25+00:00" }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "f29dca382a6485c3cbe6379f0c61230167681937" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f29dca382a6485c3cbe6379f0c61230167681937", - "reference": "f29dca382a6485c3cbe6379f0c61230167681937", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2017-06-09T14:24:12+00:00" - }, - { - "name": "symfony/process", - "version": "v3.3.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "8e30690c67aafb6c7992d6d8eb0d707807dd3eaf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/8e30690c67aafb6c7992d6d8eb0d707807dd3eaf", - "reference": "8e30690c67aafb6c7992d6d8eb0d707807dd3eaf", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "https://symfony.com", - "time": "2017-05-22T12:32:03+00:00" - }, - { - "name": "symfony/translation", - "version": "v3.3.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/translation.git", - "reference": "dc3b2a0c6cfff60327ba1c043a82092735397543" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/dc3b2a0c6cfff60327ba1c043a82092735397543", - "reference": "dc3b2a0c6cfff60327ba1c043a82092735397543", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.0" - }, - "conflict": { - "symfony/config": "<2.8", - "symfony/yaml": "<3.3" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~2.8|~3.0", - "symfony/intl": "^2.8.18|^3.2.5", - "symfony/yaml": "~3.3" - }, - "suggest": { - "psr/log": "To use logging capability in translator", - "symfony/config": "", - "symfony/yaml": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Translation\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Translation Component", - "homepage": "https://symfony.com", - "time": "2017-05-22T07:42:36+00:00" - }, { "name": "symfony/yaml", - "version": "v3.3.2", + "version": "v3.3.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063" + "reference": "1f93a8d19b8241617f5074a123e282575b821df8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063", - "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063", + "url": "https://api.github.com/repos/symfony/yaml/zipball/1f93a8d19b8241617f5074a123e282575b821df8", + "reference": "1f93a8d19b8241617f5074a123e282575b821df8", "shasum": "" }, "require": { @@ -1339,10 +986,173 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-06-02T22:05:06+00:00" + "time": "2017-06-15T12:58:50+00:00" } ], "packages-dev": [ + { + "name": "illuminate/console", + "version": "v5.4.27", + "source": { + "type": "git", + "url": "https://github.com/illuminate/console.git", + "reference": "bdc5c6f53cb474e2aeec46b6a9999fcedfb62a4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/console/zipball/bdc5c6f53cb474e2aeec46b6a9999fcedfb62a4e", + "reference": "bdc5c6f53cb474e2aeec46b6a9999fcedfb62a4e", + "shasum": "" + }, + "require": { + "illuminate/contracts": "5.4.*", + "illuminate/support": "5.4.*", + "nesbot/carbon": "~1.20", + "php": ">=5.6.4", + "symfony/console": "~3.2" + }, + "suggest": { + "guzzlehttp/guzzle": "Required to use the ping methods on schedules (~6.0).", + "mtdowling/cron-expression": "Required to use scheduling component (~1.0).", + "symfony/process": "Required to use scheduling component (~3.2)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.4-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Console\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Console package.", + "homepage": "https://laravel.com", + "time": "2017-06-10T13:11:18+00:00" + }, + { + "name": "nesbot/carbon", + "version": "1.22.1", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "reference": "7cdf42c0b1cc763ab7e4c33c47a24e27c66bfccc", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "symfony/translation": "~2.6 || ~3.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2", + "phpunit/phpunit": "~4.0 || ~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.23-dev" + } + }, + "autoload": { + "psr-4": { + "Carbon\\": "src/Carbon/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + } + ], + "description": "A simple API extension for DateTime.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "time": "2017-01-16T07:55:07+00:00" + }, + { + "name": "roots/sage-installer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/roots/sage-installer.git", + "reference": "837411acf1337d35e1b497c4ba3a8ed7cf6077fa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/roots/sage-installer/zipball/837411acf1337d35e1b497c4ba3a8ed7cf6077fa", + "reference": "837411acf1337d35e1b497c4ba3a8ed7cf6077fa", + "shasum": "" + }, + "require": { + "illuminate/console": "~5.4", + "illuminate/filesystem": "~5.4", + "symfony/process": "~3.3" + }, + "require-dev": { + "squizlabs/php_codesniffer": "^3.0" + }, + "bin": [ + "bin/sage" + ], + "type": "library", + "autoload": { + "psr-4": { + "Roots\\Sage\\Installer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Word", + "email": "ben@benword.com", + "homepage": "https://github.com/retlehs" + }, + { + "name": "QWp6t", + "email": "hi@qwp6t.me", + "homepage": "https://github.com/qwp6t" + } + ], + "description": "Sage installer.", + "keywords": [ + "FontAwesome", + "bootstrap", + "foundation", + "sage", + "tachyons", + "theme", + "wordpress" + ], + "time": "2017-07-04T17:57:47+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "2.9.1", @@ -1420,11 +1230,254 @@ "standards" ], "time": "2017-05-22T02:43:20+00:00" + }, + { + "name": "symfony/console", + "version": "v3.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "a97e45d98c59510f085fa05225a1acb74dfe0546" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/a97e45d98c59510f085fa05225a1acb74dfe0546", + "reference": "a97e45d98c59510f085fa05225a1acb74dfe0546", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3", + "symfony/dependency-injection": "~3.3", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/filesystem": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/filesystem": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2017-07-03T13:19:36+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "f29dca382a6485c3cbe6379f0c61230167681937" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/f29dca382a6485c3cbe6379f0c61230167681937", + "reference": "f29dca382a6485c3cbe6379f0c61230167681937", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-09T14:24:12+00:00" + }, + { + "name": "symfony/process", + "version": "v3.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "5ab8949b682b1bf9d4511a228b5e045c96758c30" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/5ab8949b682b1bf9d4511a228b5e045c96758c30", + "reference": "5ab8949b682b1bf9d4511a228b5e045c96758c30", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2017-07-03T08:12:02+00:00" + }, + { + "name": "symfony/translation", + "version": "v3.3.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "35dd5fb003c90e8bd4d8cabdf94bf9c96d06fdc3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/35dd5fb003c90e8bd4d8cabdf94bf9c96d06fdc3", + "reference": "35dd5fb003c90e8bd4d8cabdf94bf9c96d06fdc3", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.8", + "symfony/yaml": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0", + "symfony/intl": "^2.8.18|^3.2.5", + "symfony/yaml": "~3.3" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2017-06-24T16:45:30+00:00" } ], "aliases": [], "minimum-stability": "stable", "stability-flags": { + "roots/sage-lib": 10, "soberwp/controller": 20 }, "prefer-stable": false, diff --git a/config/assets.php b/config/assets.php new file mode 100644 index 0000000..314b0cd --- /dev/null +++ b/config/assets.php @@ -0,0 +1,31 @@ + get_theme_file_path().'/dist/assets.json', + + /* + |-------------------------------------------------------------------------- + | Assets Path URI + |-------------------------------------------------------------------------- + | + | The asset manifest contains relative paths to your assets. This URI will + | be prepended when using Sage's asset management system. Change this if + | you are using a CDN. + | + */ + + 'uri' => get_theme_file_uri().'/dist', +]; diff --git a/config/theme.php b/config/theme.php new file mode 100644 index 0000000..f048be9 --- /dev/null +++ b/config/theme.php @@ -0,0 +1,32 @@ + get_theme_file_path(), + + /* + |-------------------------------------------------------------------------- + | Theme Directory URI + |-------------------------------------------------------------------------- + | + | This is the web server URI to your theme directory. + | + | Example: + | https://example.com/app/themes/sage + | + */ + + 'uri' => get_theme_file_uri(), +]; diff --git a/config/view.php b/config/view.php new file mode 100644 index 0000000..fde5099 --- /dev/null +++ b/config/view.php @@ -0,0 +1,51 @@ + [ + get_theme_file_path().'/resources/views', + get_parent_theme_file_path().'/resources/views', + ], + + + /* + |-------------------------------------------------------------------------- + | Compiled View Path + |-------------------------------------------------------------------------- + | + | This option determines where all the compiled Blade templates will be + | stored for your application. Typically, this is within the uploads + | directory. However, as usual, you are free to change this value. + | + */ + + 'compiled' => wp_upload_dir()['basedir'].'/cache', + + + /* + |-------------------------------------------------------------------------- + | View Namespaces + |-------------------------------------------------------------------------- + | + | Blade has an underutilized feature that allows developers to add + | supplemental view paths that may contain conflictingly named views. + | These paths are prefixed with a namespace to get around the conflicts. + | A use case might be including views from within a plugin folder. + | + */ + + 'namespaces' => [ + // In your views use something like: @include(WC::some.view.or.partial.here) + 'WC' => WP_PLUGIN_DIR.'/woocommerce/templates/', + ], +]; diff --git a/resources/functions.php b/resources/functions.php index 547e6ff..88ca3f7 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -4,6 +4,9 @@ * Do not edit anything in this file unless you know what you're doing */ +use Roots\Sage\Config; +use Roots\Sage\Container; + /** * Helper function for prettying up errors * @param string $message @@ -74,21 +77,16 @@ array_map(function ($file) use ($sage_error) { * ├── STYLESHEETPATH -> /srv/www/example.com/current/web/app/themes/sage/resources/views * └── TEMPLATEPATH -> /srv/www/example.com/current/web/app/themes/sage/resources */ -if (is_customize_preview() && isset($_GET['theme'])) { - $sage_error(__('Theme must be activated prior to using the customizer.', 'sage')); -} -$sage_views = basename(dirname(__DIR__)).'/'.basename(__DIR__).'/views'; -add_filter('stylesheet', function () use ($sage_views) { - return dirname($sage_views); -}); -add_filter('stylesheet_directory_uri', function ($uri) { - return dirname($uri); -}); -if ($sage_views !== get_option('stylesheet')) { - update_option('stylesheet', $sage_views); - if (php_sapi_name() === 'cli') { - return; - } - wp_redirect($_SERVER['REQUEST_URI']); - exit(); -} +array_map( + 'add_filter', + ['theme_file_path', 'theme_file_uri', 'parent_theme_file_path', 'parent_theme_file_uri'], + array_fill(0, 4, 'dirname') +); +Container::getInstance() + ->bindIf('config', function () { + return new Config([ + 'assets' => require dirname(__DIR__).'/config/assets.php', + 'theme' => require dirname(__DIR__).'/config/theme.php', + 'view' => require dirname(__DIR__).'/config/view.php', + ]); + }, true);