Slide 1

Slide 1 text

Taking Over the World with Lithium 2012-04-12 @ NYCPHP

Slide 2

Slide 2 text

?

Slide 3

Slide 3 text

$1B

Slide 4

Slide 4 text

How to Make a BILLION DOLLARS with Lithium 2012-04-12 @ NYCPHP

Slide 5

Slide 5 text

$ li3 library extract

Slide 6

Slide 6 text

$ li3 library extract moneygram

Slide 7

Slide 7 text

$ li3 library extract moneygram moneygram created in / from / /console/command/create/ template/app.phar.gz

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

$ cd moneygram/ && sudo chmod -R 777 resources/

Slide 10

Slide 10 text

config/bootstrap/connections.php use lithium\data\Connections; Connections::add('default', array( 'type' => 'MongoDb', 'host' => 'localhost', 'database' => 'moneygram' ));

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

$ li3 create Photos

Slide 13

Slide 13 text

$ li3 create Photos Photos created in moneygram\models. PhotosController created in moneygram\controllers. PhotosTest created in moneygram\tests\cases\models. PhotosControllerTest created in moneygram\tests\cases\controllers.

Slide 14

Slide 14 text

config/routes.php Router::connect('/', 'Pages::view'); Router::connect('/', 'Photos::index');

Slide 15

Slide 15 text

config/routes.php Router::connect('/', 'Pages::view'); Router::connect('/', 'Photos::index');

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

views/photos/index.html.php

No photos! html->link('Add one', 'Photos::add'); ?>.

Slide 18

Slide 18 text

views/photos/add.html.php form->create($photo, array( 'type' => 'file' )); ?> form->field('title'); ?> form->field('description'); ?> form->field('file', array( 'type' => 'file' )); ?> form->submit('Save'); ?> form->end(); ?>

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

views/layouts/default.html.php // … html->style(array( 'bootstrap', 'bootstrap-responsive' )); ?> // …

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

models/Photos.php namespace moneygram\models; class Photos extends \lithium\data\Model { // .. protected $_meta = array('source' => 'fs.files'); protected $_schema = array( '_id' => array('type' => '_id'), 'title' => array('type' => 'string'), 'description' => array('type' => 'string'), ); }

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

config/routes.php Router::connect( '/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null) ); Router::connect( '/{:controller}/{:action}/{:id:[0-9a-f]{24}}' );

Slide 27

Slide 27 text

views/photos/view.html.php

title; ?>

description; ?>

html->image( "/photos/view/{$photo->_id}.jpg", array('alt' => $photo->title) ); ?>

Slide 28

Slide 28 text

config/bootstrap/media.php Media::type('jpg', 'image/jpeg', array( 'cast' => false, 'encode' => function($data) { return $data['photo']->file->getBytes(); } )); config/bootstrap.php require __DIR__ . '/bootstrap/media.php';

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

views/photos/index.html.php
  • html->image("/photos/view/{$photo->_id}.jpg"); ?>
    html->link( $photo->title, array('Photos::view', 'id' => $photo->_id) ); ?>

Slide 31

Slide 31 text

views/photos/view.html.php

html->link( 'Age-ify!', array('Photos::edit', 'id' => $photo->_id), array('class' => 'btn btn-info') ); ?>

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

$ git submodule add git://github.com/avalanche123/Imagine.git libraries/_source/Imagine Cloning into libraries/_source/Imagine... .... .... $ cd libraries/ && ln -s ./_source/Imagine/lib/Imagine Imagine

Slide 34

Slide 34 text

config/bootstrap/libraries.php Libraries::add('Imagine');

Slide 35

Slide 35 text

controllers/PhotosController.php use Imagine\Imagick\Imagine; use moneygram\extensions\imagine\SepiaToneFilter; class PhotosController extends \lithium\action\Controller { public function edit() { // ... } }

Slide 36

Slide 36 text

controllers/PhotosController.php public function edit() { set_time_limit(0); $photo = Photos::first($this->request->id); $imagine = new Imagine(); $filter = new SepiaToneFilter($imagine); // ... }

Slide 37

Slide 37 text

controllers/PhotosController.php public function edit() { // ... $new = $filter->apply($imagine->load( $photo->file->getBytes() )); $photo->delete(); $photo = Photos::create(array( '_id' => $photo->_id, 'title' => $photo->title, 'file' => $new->get('jpg') )); $photo->save(); return $this->redirect(array( 'Photos::view', 'id' => $photo->_id )); }

Slide 38

Slide 38 text

extensions/imagine/SepiaToneFilter.php namespace moneygram\extensions\imagine; use Imagine\Image\Box; use Imagine\Image\Point; use Imagine\Image\Color; class SepiaToneFilter implements \Imagine\Filter\FilterInterface { // ... }

Slide 39

Slide 39 text

extensions/imagine/SepiaToneFilter.php public function apply(\Imagine\Image\ImageInterface $image) { $new = $this->_imagine->create($image->getSize(), new Color('fff')); for ($x = 0; $x < $image->getSize()->getWidth(); $x++) { for ($y = 0; $y < $image->getSize()->getHeight(); $y++) { $position = new Point($x, $y); $pixel = $image->getColorAt($position); $r = $pixel->getRed(); $g = $pixel->getGreen(); $b = $pixel->getBlue(); $r = min(array((0.272 * $r) + (0.534 * $g) + (0.131 * ($b)), 255)); $g = min(array((0.349 * $r) + (0.686 * $g) + (0.168 * ($b)), 255)); $b = min(array((0.393 * $r) + (0.769 * $g) + (0.189 * ($b)), 255)); $r = ($r > 255) ? 255 : $r; $g = ($g > 255) ? 255 : $g; $b = ($b > 255) ? 255 : $b; $pixel = new Color(array($r, $g, $b)); $new->draw()->dot($position, $pixel); } } return $new; }

Slide 40

Slide 40 text

No content