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
| use lithium\core\Environment; | |
| $request = new lithium\action\Request(); | |
| Environment::is(function($request) { | |
| switch (true) { | |
| case (in_array($request->env('SERVER_ADDR'), array('::1', '127.0.0.1'))): | |
| return 'development'; | |
| case ($request->env('HTTP_HOST') == 'foobar.com.au'): | |
| return 'staging'; |
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
| Logger::config(array( | |
| 'default' => array( | |
| 'adapter' => 'File', | |
| 'path' => dirname(__DIR__) . '/logs/', | |
| 'file' => function($details, $config) { | |
| return $details['priority'] . '-' . date('d-m-Y') '.log'; | |
| } | |
| ) | |
| )); |
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 app\extensions\helper; | |
| use Assetic\AssetWriter; | |
| use Assetic\AssetManager; | |
| use Assetic\FilterManager; | |
| use Assetic\Asset\AssetCache; | |
| use Assetic\Asset\AssetCollection; | |
| use Assetic\Asset\FileAsset; |
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 | |
| $coords = Geocoder::find('google', "Sydney, Australia"); | |
| // Within a box | |
| $files = Files::find('within', [ | |
| 'conditions' => [ | |
| 'location' => [ | |
| '$within' => [ | |
| '$box' => [ |
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 | |
| Posts::applyFilter('find', function($self, $params, $chain) { | |
| $key = // Make a cache key from $params['options'] | |
| if ($result = Cache::read('default', $key)) { | |
| return $result; | |
| } | |
| $result = $chain->next($self, $params, $chain); | |
| Cache::write('default', $key, $result); | |
| return $result; |
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 | |
| $query = new Query(array( | |
| 'type' => 'read', | |
| 'model' => 'app\models\Post', | |
| 'fields' => array('Post.title', 'Post.body'), | |
| 'conditions' => array('Post.id' => new Query(array( | |
| 'type' => 'read', | |
| 'fields' => array('post_id'), | |
| 'model' => 'app\models\Tagging', |
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 | |
| $posts = Posts::findAllBySomeCondition(); | |
| $posts->first(function($post) { | |
| return $post->published == true; | |
| }); | |
| $posts->each(function($post) { | |
| return $post->counter++; |
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 app\models; | |
| class Posts extends \lithium\data\Model { | |
| protected $_meta = array( | |
| 'key' => 'custom_id', | |
| 'source' => 'custom_posts_table', | |
| 'connection' => 'legacy_mysql_db' |
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 | |
| Router::connect('/{:user}/{:controller}/{:action}', array(), function($request) { | |
| if (!Users::count(array('conditions' => array('user' => $request->user)))) { | |
| return false; | |
| } | |
| return $request; | |
| }); | |
| Router::connect('/', array(), function($request) { |
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 | |
| $request->detect('iPhone', array('HTTP_USER_AGENT', '/iPhone/')); | |
| $isiPhone = $request->is('iPhone'); | |
| $request->detect('custom', function($request) { | |
| if ($value = $request->env("HTTP_WHATEVER")) { | |
| // Do something with $value | |
| } | |
| return false; | |
| }); |