Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Lithium @lonestarphp

gwoo
July 02, 2012

Intro to Lithium @lonestarphp

Every framework claims to help you build the next killer app in less time and with less effort , but do they really help you do it your way? In this tactical tour-de-force, you'll learn how Lithium pulls together different tools, technologies, and paradigms to assist even the most complex and diabolical plans. By the end of the session, you'll know each step in the process required to get from zero to Instragram using Lithium.

gwoo

July 02, 2012
Tweet

More Decks by gwoo

Other Decks in Technology

Transcript

  1. $1B

  2. $ li3 library extract moneygram moneygram created in /<path to

    app> from / <path to lithium>/console/command/create/ template/app.phar.gz
  3. $ li3 create Photos Photos created in models/Photos.php. PhotosController created

    in controllers/PhotosController.php. PhotosTest created in tests/cases/models/PhotosTest.php PhotosControllerTest created in tests/cases/controllers/PhotosControllerTest.php
  4. views/photos/index.html.php <?php if (!count($photos)): ?> <p> No photos! <?=$this->html->link('Add one',

    'Photos::add'); ?>. </p> <?php endif ?> <ul> <?php foreach ($photos as $photo): ?> <li><?=$this->html->link($photo->title, array('Photos::view', 'id' => $photo->_id)); ?></li> <?php endforeach ?> </ul>
  5. views/photos/add.html.php <?=$this->form->create($photo, array( 'type' => 'file' )); ?> <?=$this->form->field('title'); ?>

    <?=$this->form->field('description'); ?> <?=$this->form->field('file', array( 'type' => 'file' )); ?> <?=$this->form->submit('Save'); ?> <?=$this->form->end(); ?>
  6. 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';
  7. views/photos/index.html.php <?php foreach ($photos as $photo): ?> <div class="photo" style="width:220px;text-

    align:center;float:left"> <?=$this->html->image("/photos/view/{$photo->_id}.jpe", array('width'=> 200)); ?> <p><?=$this->html->link($photo->title, array('Photos::view', 'id' => $photo->_id)); ?></p> </div> <?php endforeach ?>
  8. controllers/PhotosController.php use Imagine\Imagick\Imagine; class Photos extends \lithium\data\Model { public static

    $_classes = array( 'sepia' => 'moneygram\extensions\imagine\SepiaToneFilter' ); public function apply($photo, $type, array $options = array()) { set_time_limit(0); $imagine = new Imagine(); $filter = static::$_classes[$type]; $class = new $filter($imagine); $new = $class->apply($imagine->load( $photo->file->getBytes() )); return $new; } }
  9. controllers/PhotosController.php public function edit() { $photo = Photos::find($this->request->id); $new =

    $photo->apply('sepia'); $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 )); }
  10. 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; }
  11. li3_docs: automatic docs from blocks li3_quality: commit the right code

    li3_access: authorize users and actions li3_resources: declarative parameter support > 200 Plugins