IMPORTANT: Per accedir als fitxer de subversion: http://acacha.org/svn (sense password). Poc a poc s'aniran migrant els enllaços. Encara però funciona el subversion de la farga però no se sap fins quan... (usuari: prova i la paraula de pas 123456)

See also:

SOLID principles example with Laravel

Solution could be found at tag solution_case_o:

 https://github.com/acacha/solid_laravel/tree/solution_case_o

Controller:

<?php namespace SolidLaravel\Http\Controllers;

use SolidLaravel\Http\Requests;
use SolidLaravel\Http\Controllers\Controller;

use Illuminate\Http\Request;
use SolidLaravel\InvoiceReport;
use SolidLaravel\Output\InvoiceShowHtml;
use SolidLaravel\Output\InvoiceShowText;
use SolidLaravel\Repositories\InvoiceRepository;

class InvoiceController extends Controller {

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show invoice
     *
     * @return Response
     */
    public function index()
    {
        $invoice = new InvoiceReport(new InvoiceRepository(),1);
        return view('invoice')->with('totalAmmount',$invoice->show(new InvoiceShowHtml()));
        //return view('invoice')->with('totalAmmount',$invoice->show(new InvoiceShowText()));
    }

}

You can see commented and example of how to use TEXT version.

At Ouput/Contracts folder we create the new Interface:

<?php
/**
 * Created by Sergi Tur Badenas @2015
 * http://acacha.org/sergitur
 * http://acacha.org
 * Date: 08/04/15
 * Time: 18:22
 */

namespace SolidLaravel\Output\Contracts;


interface InvoiceShowInterface {

    public function show($invoice);

}

An in Ouput Folder two implementations (HTML and TEXT):

<?php
/**
 * Created by Sergi Tur Badenas @2015
 * http://acacha.org/sergitur
 * http://acacha.org
 * Date: 08/04/15
 * Time: 18:24
 */

namespace SolidLaravel\Output;

use SolidLaravel\Output\Contracts\InvoiceShowInterface;

class InvoiceShowHtml implements InvoiceShowInterface {

    public function show($invoice)
    {
        return "<strong>" . $invoice->totalAmmount . " </strong>";
    }
}
<?php
/**
 * Created by Sergi Tur Badenas @2015
 * http://acacha.org/sergitur
 * http://acacha.org
 * Date: 08/04/15
 * Time: 18:24
 */

namespace SolidLaravel\Output;

use SolidLaravel\Output\Contracts\InvoiceShowInterface;

class InvoiceShowText implements InvoiceShowInterface {

    public function show($invoice)
    {
        return $invoice->totalAmmount;
    }
}