Composer, Traits, Generators, PRG, Start Version Control




CS174

Chris Pollett

Oct 19, 2016

Outline

Composer

Composer

Example Composer Project Using Yioop

Comments on the Example

Traits

Exceptions

Generators

Variable and Anonymous Functions

Our Website Design Paradigm So Far...

POST REDIRECT GET

Let's Build Something

Consider the following three files worth of code:

<?php
// View.php
abstract class View
{
    public $layout;
    public function __construct(string $layout) 
    {
        $this->layout = new $layout($this);
    }
    public final function display($data = [])
    {
        $this->layout->renderHeader($data);
        $this->render($data);
        $this->layout->renderFooter($data);
    }
    public abstract function render($data = []);
}
<?php
//Layout.php
abstract class Layout
{
    public $view;
    public function __construct(View $view)
    //notice type hinting allowed for objects
    {
        $this->view = $view;
    }
    public abstract function renderHeader($data);
    public abstract function renderFooter($data);
}
<?php
//index.php
require_once "LetsBuildView.php";
require_once "WebLayout.php";

$data['title'] = "Let's Build Something";
$data['content'] = "Yippee! It works!";
$view = new LetsBuildView("WebLayout");
$view->display($data);

Assume the file index.php is the entry point into the above program. Create concrete implementations of the classes View and Layout called LetsBuildView and WebLayout such that the output of the above is an HTML 5 web page with title $data['title'], the body of the page has $data['title'] in an h1 tag, and has $data['content'] in a paragraph tag.

Post your solutions to the Oct. 19 Let's Build Something Thread