Skip to content

Commit

Permalink
Started migration to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
joelambert committed Dec 9, 2017
1 parent 22e6dfc commit aeb0694
Show file tree
Hide file tree
Showing 41 changed files with 458 additions and 642 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 Rareloop http://rareloop.com
Copyright (c) 2015-17 Rareloop http://rareloop.com

The MIT License (MIT)

Expand Down
323 changes: 178 additions & 145 deletions README.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Exceptions;

use Exception;
use Psr\Http\Message\ResponseInterface;
use Rareloop\Lumberjack\Exceptions\Handler as LumberjackHandler;
use Zend\Diactoros\ServerRequest;

class Handler extends LumberjackHandler
{
protected $dontReport = [];

public function report(Exception $e)
{
parent::report($e);
}

public function render(ServerRequest $request, Exception $e) : ResponseInterface
{
return parent::render($request, $e);
}
}
File renamed without changes.
24 changes: 24 additions & 0 deletions app/Http/Lumberjack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http;

use Rareloop\Lumberjack\Http\Lumberjack as LumberjackCore;

class Lumberjack extends LumberjackCore
{
public function addToContext($context)
{
$context['is_home'] = is_home();
$context['is_front_page'] = is_front_page();
$context['is_logged_in'] = is_user_logged_in();

// In Timber, you can use TimberMenu() to make a standard Wordpress menu available to the
// Twig template as an object you can loop through. And once the menu becomes available to
// the context, you can get items from it in a way that is a little smoother and more
// versatile than Wordpress's wp_nav_menu. (You need never again rely on a
// crazy "Walker Function!")
$context['menu'] = new Menu('main-nav');

return $context;
}
}
7 changes: 3 additions & 4 deletions lumberjack/src/Core/MenuItem.php → app/Menu/Item.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

namespace Lumberjack\Core;
namespace App\Menu;

use Timber\MenuItem as TimberMenuItem;

class MenuItem extends TimberMenuItem
class Item extends TimberMenuItem
{
public $PostClass = 'Lumberjack\PostTypes\Post';

public $PostClass = 'Rareloop\Lumberjack\Post';
public $listItemClass = 'page-list__item';

public function __construct($data)
Expand Down
11 changes: 11 additions & 0 deletions app/Menu/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Menu;

use Timber\Menu as TimberMenu;

class Menu extends TimberMenu
{
public $MenuItemClass = 'App\Menu\Item';
public $PostClass = 'Rareloop\Lumberjack\Post';
}
Empty file added app/PostTypes/.gitkeep
Empty file.
15 changes: 15 additions & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Rareloop\Lumberjack\Application;
use App\Exceptions\Handler;
use Rareloop\Lumberjack\Exceptions\HandlerInterface;

$autoloader = require_once('autoload.php');

$autoloader('App\\', dirname(__DIR__) . '/app/');

$app = new Application(dirname(__DIR__));

$app->bind(HandlerInterface::class, $app->make(Handler::class));

return $app;
38 changes: 38 additions & 0 deletions bootstrap/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

return function ($prefix, $baseDir) {
/**
* An example of a project-specific implementation.
*
* After registering this autoload function with SPL, the following line
* would cause the function to attempt to load the \Foo\Bar\Baz\Qux class
* from /path/to/project/src/Baz/Qux.php:
*
* new \Foo\Bar\Baz\Qux;
*
* @param string $class The fully-qualified class name.
* @return void
*/
spl_autoload_register(function ($class) use ($prefix, $baseDir) {
// does the class use the namespace prefix?
$len = strlen($prefix);

if (strncmp($prefix, $class, $len) !== 0) {
// no, move to the next registered autoloader
return;
}

// get the relative class name
$relativeClass = substr($class, $len);

// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';

// if the file exists, require it
if (file_exists($file)) {
require $file;
}
});
};
31 changes: 31 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

return [
/**
* The current application environment
*/
'environment' => getenv('WP_ENV'),

/**
* Is debug mode enabled?
*/
'debug' => WP_DEBUG ?? false,

/**
* List of providers to initialise during app boot
*/
'providers' => [
Rareloop\Lumberjack\Providers\RouterServiceProvider::class,
Rareloop\Lumberjack\Providers\WordPressControllersServiceProvider::class,
Rareloop\Lumberjack\Providers\TimberServiceProvider::class,
Rareloop\Lumberjack\Providers\ImageSizesServiceProvider::class,
Rareloop\Lumberjack\Providers\CustomPostTypesServiceProvider::class,
Rareloop\Lumberjack\Providers\MenusServiceProvider::class,
Rareloop\Lumberjack\Providers\LogServiceProvider::class,
Rareloop\Lumberjack\Providers\ThemeSupportServiceProvider::class,
],

'themeSupport' => [
'post-thumbnail',
],
];
15 changes: 15 additions & 0 deletions config/images.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

return [
/**
* List of image sizes to register, each image size looks like:
* [
* 'name' => 'thumb'
* 'width' => 100,
* 'height' => 200,
* 'crop' => true,
* ]
*/
'sizes' => [
],
];
10 changes: 10 additions & 0 deletions config/menus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
/**
* List of menus to register with WordPress during bootstrap
*/
'menus' => [
'main-nav' => __('Main Navigation'),
],
];
10 changes: 10 additions & 0 deletions config/posttypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
/**
* List all the sub-classes of Rareloop\Lumberjack\Post in your app that you wish to
* automatically register with WordPress as part of the bootstrap process.
*/
'register' => [
],
];
10 changes: 10 additions & 0 deletions config/timber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
/**
* List of directories to load Twig files from
*/
'paths' => [
'views',
],
];
18 changes: 11 additions & 7 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?php

use Timber\Timber;
use App\Http\Lumberjack;

// Timber::$cache = true;
// Create the Application Container
$app = require_once('bootstrap/app.php');

Timber::$dirname = [
'views',
'views/templates',
];
// Bootstrap Lumberjack from the Container
$lumberjack = $app->make(Lumberjack::class);
$lumberjack->bootstrap();

require_once('lumberjack/bootstrap.php');
// Import our routes file
require_once('routes.php');

// Set global params in the Timber context
add_filter('timber_context', [$lumberjack, 'addToContext']);
23 changes: 13 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists
*
* Methods for TimberHelper can be found in the /lib sub-directory
*
* @package WordPress
* @subpackage Timber
* @since Timber 0.1
*/

namespace App;

use Rareloop\Lumberjack\Http\Responses\TimberResponse;
use Rareloop\Lumberjack\Post;
use Timber\Timber;
use Lumberjack\PostTypes\Post;

$context = Timber::get_context();
$context['posts'] = Post::all();
class IndexController
{
public function handle()
{
$context = Timber::get_context();
$context['posts'] = Post::all();

Timber::render(['posts.twig'], $context);
return new TimberResponse('templates/posts.twig', $context);
}
}
41 changes: 0 additions & 41 deletions lumberjack/autoload.php

This file was deleted.

48 changes: 0 additions & 48 deletions lumberjack/bootstrap.php

This file was deleted.

Loading

0 comments on commit aeb0694

Please sign in to comment.