This file contains hidden or 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 namespace Acme\Storage\Eloquent; | |
use Acme\Storage\PostRepositoryInterface; | |
use Acme\Models\Post; | |
class PostRepository implements PostRepositoryInterface { | |
public function paginate($perPage = null, $columns = array('*')) | |
{ | |
return Post::paginate($perPage, $columns); |
This file contains hidden or 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 namespace Acme\Storage; | |
interface PostRepositoryInterface { | |
public function paginate($perPage = null, $columns = array('*')); | |
public function findOrFail($id, $columns = array('*')); | |
// ...etc | |
} |
This file contains hidden or 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 namespace Acme\Controllers; | |
use Acme\Storage\PostRepository; | |
class PostController extends BaseController { | |
private $postRepository; | |
public function __construct(PostRepository $postRepository = null) | |
{ |
This file contains hidden or 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 namespace Acme\Storage; | |
use Acme\Models\Post; | |
class PostRepository { | |
public function paginate($perPage = null, $columns = array('*')) | |
{ | |
return Post::paginate($perPage, $columns); | |
} |
This file contains hidden or 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 namespace Acme\Controllers; | |
use Acme\Models\Post; | |
class PostController extends BaseController { | |
public function index() | |
{ | |
$posts = Post::paginate(20); | |
return View::make('post.index', compact('posts')); |
This file contains hidden or 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 | |
// get the environment variable and parse it: | |
$url = parse_url(getenv('DATABASE_URL')); | |
// construct the data source name: | |
$scheme = $url['scheme']; | |
$host = $url['host'] . ':' . $url['port']; | |
$dbname = trim($url['path'], '/'); // '/application_db' -> 'application_db' | |
$dsn = "{$scheme}:host={$host};dbname={$path}"; |
This file contains hidden or 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 | |
$url = parse_url('mysql://dbuser:dbpass@localhost:4567/application_db'); | |
var_dump($url); |
This file contains hidden or 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 | |
// Initialising a DB connection from environment vars... | |
$dbHost = getenv('DB_HOST'); | |
$dbName = getenv('DB_NAME'); | |
$dbUser = getenv('DB_USER'); | |
$dbPass = getenv('DB_PASS'); | |
$pdo = new \PDO("mysql:host={$dbHost};dbname={$dbName}", $dbUser, $dbPass); |
This file contains hidden or 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 | |
namespace Service; | |
class TwitterAPI | |
{ | |
private $httpClient; | |
public function __construct($httpClient = null) | |
{ | |
$this->httpClient = $httpClient; |
This file contains hidden or 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 | |
namespace Model; | |
class Product { /* etc... */ } | |
class Order { /* etc... */ } | |
class Customer { /* etc... */ } | |
/* * * * * * * * * * * * * * * * */ |