SlideShare a Scribd company logo
1 of 41
Download to read offline
LARAVEL 4
TIHOMIR
OPACIC
PRESENTED
BY
PACKAGE DEVELOPMENT
THE PHP FRAMEWORK FOR WEB ARTISANS.
ABOUT LARAVEL 4
RESTful Routing
Beautiful Templating
Proven Foundation
Great Community
Command Your Data
Ready For Tomorrow
Composer Powered
Red, Green, Refactor
HISTORY
•CodeIgniter > Sparks
•FuelPHP > Cells
•Laravel > Bundles
•CakePHP > The Bakery
•ZF2 > Modules
•RubyGems
•NodeJS Package Manager
•PEAR
•PEAR2
PACKAGES
PEAR PHP INSPIRATION
Got a good PHP class? Is it only on GitHub, or
maybe it's just sitting around on your blog?
Stop that. Stop that right now.
Make it into a Composer package and host it on
Packagist.
HISTORY
”
http://philsturgeon.co.uk/blog/2012/03/packages-the-way-forward-for-php (*Phil Sturgeon: Pyro CMS)
Composer is a tool for
dependency management
in PHP.
It allows you to declare
the dependent libraries
your project needs and it
will install them in your
project for you.
COMPOSER
http://getcomposer.org/
Packagist is the main
Composer repository. It
aggregates all sorts of
PHP packages that are
installable with Composer.
PACKAGIST
https://packagist.org/
1 2 3 4
CODE REUSABILITY MODULAR APPS OPENSOURCE
LEVEREGE
FRAMEWORK DEV
MADE EASIER
BENEFITS
Main benefits while using Composer and Packagist to get or
publish PHP Packages.
2012-04 2012-09 2013-02 2013-08
950000020000001000000100000
PACKAGES INSTALLED
Source: https://packagist.org/statistics
1 2 3 4
INTRODUCED IN V.4
WERE BUNDLES IN V.3
FRAMEWORK
GROWTH BOOST
ENTIRELY
MADE OF PACKAGES
WORKBENCH
PACKAGE DEV TOOL
LARAVEL 4
Packages in Laravel 4 PHP Framework
INSTALL COMPOSER
Installation instructions: http://getcomposer.org/doc/01-basic-usage.md#installation
COMPOSER.JSON
{
"name": "orangehill/zgphpcon2013",
"description": "Laravel 4 workbench package generation walkthrough.",
"authors": [
{
"name": "Tihomir Opacic",
"email": "tihomir.opacic@orangehilldev.com"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},
"autoload": {
"psr-0": {
"OrangehillZgphpcon2013": "src/"
}
},
"minimum-stability": "dev"
}
VENDOR / NAME
DESCRIPTION
AUTHORS
DEPENDENCY
PSR-0 AUTOLOADING INFO
more: http://www.sitepoint.com/autoloading-and-the-psr-0-standard/ 
Also Available in Serbian:
Razvoj web aplikacija uz
pomoć Laravel radnog
okvira verzije 4 za
početnike
Slaviša Petrović 
@slawisha75
CODEBRIGHT
Dayle Rees @daylerees
https://leanpub.com/codebright-sr https://leanpub.com/codebright
COMPOSER.JSON
$ php composer.phar install
*phar: PHP Archive - entire PHP applications in a single file
$ composer install
*If you did a global install and do not have the phar in that directory run this instead
LARAVEL
WORKBENCH
14 STEP WALKTHROUGH
https://github.com/orangehill/Laravel-Workbench-Walkthrough
SIMPLICITY
14 STEP WALKTHROUGH
https://github.com/orangehill/Laravel-Workbench-Walkthrough
IT’S SO
EASY!
Edit /app/config/workbench.php and set your name and email. This
info is used later to populate the composer.json file.
PACKAGE GENERATION
Laravel Workbench Walkthrough
1 Edit workbench config file
Use Command Line Interface (CLI) to navigate to Laravel 4 root folder,
and then run:
Note that orangehill represents a vendor (company name, personal
name etc.), and walkthrough represents a package name.
PACKAGE GENERATION
Laravel Workbench Walkthrough
2 Run CLI (Command Line Interface) command
php artisan workbench orangehill/walkthrough --resources
Use your CLI to navigate to /workbench/orangehill/walkthrough and
verify that the package structure has been created.
PACKAGE GENERATION
Laravel Workbench Walkthrough
3 Navigate to package directory
Open /app/config/app.php to add a Service Provider to the end of the
providers array:
PACKAGE SETUP
Laravel Workbench Walkthrough
4 Add a Service Provider
'providers' => array(
// --
'OrangehillWalkthroughWalkthroughServiceProvider',
),
To create a main package class generate the file named
Walkthrough.php inside a path /workbench/orangehill/walkthrough/
src/Orangehill/Walkthrough/ with the following code inside:
PACKAGE SETUP
Laravel Workbench Walkthrough
5 Create Main Package Class
<?php namespace OrangehillWalkthrough;
class Walkthrough {
public static function hello(){
return "What's up Zagreb!";
}
}
Edit the Package Service Provider file /workbench/orangehill/
walkthrough/src/Orangehill/Walkthrough/
WalkthroughServiceProvider.php and make sure that the register
method looks like this:
PACKAGE SETUP
Laravel Workbench Walkthrough
6 Register the new class with the Laravel’s IoC
Container
public function register()
{
$this->app['walkthrough'] = $this->app->share(function($app)
{
return new Walkthrough;
});
}
Note: If your service provider cannot be found, run the php artisan
dump-autoload command from your application's root directory.
PACKAGE SETUP
Laravel Workbench Walkthrough
6 NOTE!
Although generating a facade is not necessary, Facade allows you to
do something like this:
FACADE GENERATION
Laravel Workbench Walkthrough
echo Walkthrough::hello();
Create a folder named Facades under following path /workbench/
orangehill/walkthrough/src/Orangehill/Walkthrough/
FACADE GENERATION
Laravel Workbench Walkthrough
7 Create a Facades folder
Inside the Facades folder create a file named Walkthrough.php with the
following content:
PACKAGE SETUP
Laravel Workbench Walkthrough
8 Create a Facade class
<?php namespace OrangehillWalkthroughFacades;
use IlluminateSupportFacadesFacade;
class Walkthrough extends Facade {
protected static function getFacadeAccessor() { return
'walkthrough'; }
}
Add the following to the register method of your Service Provider file:
This allows the facade to work without the adding it to the Alias array
in app/config/app.php
PACKAGE SETUP
Laravel Workbench Walkthrough
9 Edit a register method of your
Service Provider file
$this->app->booting(function()
{
$loader = IlluminateFoundation
AliasLoader::getInstance();
$loader->alias('Walkthrough', 'OrangehillWalkthrough
FacadesWalkthrough');
});
Edit your /app/routes.php file and add a route to test if a package
works:
BROWSER TEST
Laravel Workbench Walkthrough
10 Edit a routes file
Route::get('/hello', function(){
echo Walkthrough::hello();
});
If all went well you should see the output in your browser after visiting
the test URL:
BROWSER TEST
Laravel Workbench Walkthrough
What's up Zagreb!
First, let's modify the /workbench/orangehill/walkthrough/src/
Orangehill/Walkthrough/Walkthrough.php file to accept an optional
parameter and echo out a message that we can observe in our CLI:
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
11 Modify a main package class
public static function hello($verb = 'up'){
if (PHP_SAPI == 'cli') echo "What's $verb Zagreb?n";
return "What's up Zagreb?";
}
Create a file WalkthroughCommand.php inside /workbench/
orangehill/walkthrough/src/Orangehill/Walkthrough/ folder with
following content (code is pretty much self-explanatory):
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
12 Create a Command class
<?php namespace OrangehillWalkthrough;
use IlluminateConsoleCommand;
use SymfonyComponentConsoleInputInputOption;
use SymfonyComponentConsoleInputInputArgument;
class WalkthroughCommand extends Command {
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
12 Create a Command class
/**
* The console command name.
*
* @var string
*/
protected $name = 'walkthrough';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run the Walkthrough Package
hello() method from command line.';
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
12 Create a Command class
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
12 Create a Command class
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
app('walkthrough')->hello($this->argument('verb'));
}
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
12 Create a Command class
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('verb', InputArgument::REQUIRED, 'verb'),
);
}
}
Modify Service Provider file register method to include the following
code:
ARTISAN CLI SUPPORT
Laravel Workbench Walkthrough
13 Modify Service Provider file register method
$this->app['command.walkthrough'] = $this->app-
>share(function($app)
{
return new WalkthroughCommand;
});
$this->commands('command.walkthrough');
Run the test from CLI in your project root folder:
CLI TEST
Laravel Workbench Walkthrough
14 Run a test from CLI
php artisan walkthrough cooking
If all went well:
CLI TEST
Laravel Workbench Walkthrough
What's cooking Zagreb!
•Time/Date Management Classes
•Various API Wrapper Classes
•PDF Creation Libraries
•Image Manipulation Libraries
PACKAGES
FRAMEWORK AGNOSTIC PACKAGES
PACKAGES
Satis - Package Repository Generator
https://github.com/composer/satis
PRIVATE REPOSITORIES
Orange Hill
Djordja Stanojevica 9b, 11000 Belgrade, Serbia
MAP
CONTACT US
WWW.ORANGEHILLDEV.COM
OFFICE@ORANGEHILLDEV.COM
+381.64.167.7367
FACEBOOK
WWW.FACEBOOK.COM/ORANGEHILLDEV
TWITTER
WWW.TWITTER.COM/ORANGEHILLDEV
LINKEDIN
WWW.LINKEDIN.COM/COMPANY/ORANGE-HILL
BLOG
WWW.ORANGEHILLDEV.COM
FOLLOW US
Orange Hill
Djordja Stanojevica 9b, 11000 Belgrade, Serbia

More Related Content

What's hot

Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90minsLarry Cai
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014biicode
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to productionSean Hess
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)Robert Swisher
 
Composer the right way - SunshinePHP
Composer the right way - SunshinePHPComposer the right way - SunshinePHP
Composer the right way - SunshinePHPRafael Dohms
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
[Community Open Camp] 給 PHP 開發者的 VS Code 指南[Community Open Camp] 給 PHP 開發者的 VS Code 指南
[Community Open Camp] 給 PHP 開發者的 VS Code 指南Shengyou Fan
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Kirill Chebunin
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsMark Baker
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf Conference
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in phpBo-Yi Wu
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Clark Everetts
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with ComposerJason Grimes
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPANdaoswald
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flaskjuzten
 

What's hot (20)

Learn flask in 90mins
Learn flask in 90minsLearn flask in 90mins
Learn flask in 90mins
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Continuous Quality Assurance
Continuous Quality AssuranceContinuous Quality Assurance
Continuous Quality Assurance
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)
 
Composer the right way - SunshinePHP
Composer the right way - SunshinePHPComposer the right way - SunshinePHP
Composer the right way - SunshinePHP
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
C++ for the Web
C++ for the WebC++ for the Web
C++ for the Web
 
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
[Community Open Camp] 給 PHP 開發者的 VS Code 指南[Community Open Camp] 給 PHP 開發者的 VS Code 指南
[Community Open Camp] 給 PHP 開發者的 VS Code 指南
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
30 Minutes To CPAN
30 Minutes To CPAN30 Minutes To CPAN
30 Minutes To CPAN
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 
Maven 3.0 at Øredev
Maven 3.0 at ØredevMaven 3.0 at Øredev
Maven 3.0 at Øredev
 

Viewers also liked

SITCON2014 LT 快倒的座位表
SITCON2014 LT 快倒的座位表SITCON2014 LT 快倒的座位表
SITCON2014 LT 快倒的座位表Yi Tseng
 
Beginning Jquery In Drupal Theming
Beginning Jquery In Drupal ThemingBeginning Jquery In Drupal Theming
Beginning Jquery In Drupal ThemingRob Knight
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersYehuda Katz
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersJonathan Sharp
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend FrameworkBrett Harris
 
PHPBootcamp - Zend Framework
PHPBootcamp - Zend FrameworkPHPBootcamp - Zend Framework
PHPBootcamp - Zend Frameworkthomasw
 
Intro to Laravel 4 : By Chris Moore
Intro to Laravel 4 : By Chris Moore Intro to Laravel 4 : By Chris Moore
Intro to Laravel 4 : By Chris Moore kareerme
 
Node js presentation
Node js presentationNode js presentation
Node js presentationshereefsakr
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Application of nodejs in epsilon mobile
Application of nodejs in epsilon mobileApplication of nodejs in epsilon mobile
Application of nodejs in epsilon mobileTony Vo
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Ryan Mauger
 
Node lt
Node ltNode lt
Node ltsnodar
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentShahar Evron
 
Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.jsJitendra Zaa
 

Viewers also liked (20)

SITCON2014 LT 快倒的座位表
SITCON2014 LT 快倒的座位表SITCON2014 LT 快倒的座位表
SITCON2014 LT 快倒的座位表
 
Beginning Jquery In Drupal Theming
Beginning Jquery In Drupal ThemingBeginning Jquery In Drupal Theming
Beginning Jquery In Drupal Theming
 
jQuery Presentation to Rails Developers
jQuery Presentation to Rails DevelopersjQuery Presentation to Rails Developers
jQuery Presentation to Rails Developers
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend Framework
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
PHPBootcamp - Zend Framework
PHPBootcamp - Zend FrameworkPHPBootcamp - Zend Framework
PHPBootcamp - Zend Framework
 
Big Data loves JS
Big Data loves JSBig Data loves JS
Big Data loves JS
 
Intro to Laravel 4 : By Chris Moore
Intro to Laravel 4 : By Chris Moore Intro to Laravel 4 : By Chris Moore
Intro to Laravel 4 : By Chris Moore
 
Node js presentation
Node js presentationNode js presentation
Node js presentation
 
Laravel tips
Laravel tipsLaravel tips
Laravel tips
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Application of nodejs in epsilon mobile
Application of nodejs in epsilon mobileApplication of nodejs in epsilon mobile
Application of nodejs in epsilon mobile
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
 
Frontend technologies
Frontend technologiesFrontend technologies
Frontend technologies
 
Node lt
Node ltNode lt
Node lt
 
Zend Framework Components for non-framework Development
Zend Framework Components for non-framework DevelopmentZend Framework Components for non-framework Development
Zend Framework Components for non-framework Development
 
Starting with Node.js
Starting with Node.jsStarting with Node.js
Starting with Node.js
 

Similar to Laravel 4 package development

Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertKaty Slemon
 
How to install laravel framework in windows
How to install laravel framework in windowsHow to install laravel framework in windows
How to install laravel framework in windowsSabina Sadykova
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New FeaturesJoe Ferguson
 
Laravel and artisan cli
Laravel and artisan cliLaravel and artisan cli
Laravel and artisan cliSayed Ahmed
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialJoe Ferguson
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel frameworkPhu Luong Trong
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A GrzesikApache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesikmfrancis
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressJeroen van Dijk
 
Dockerize Laravel Application
Dockerize Laravel ApplicationDockerize Laravel Application
Dockerize Laravel ApplicationAfrimadoni Dinata
 
Laravel Code Generators and Packages
Laravel Code Generators and PackagesLaravel Code Generators and Packages
Laravel Code Generators and PackagesPovilas Korop
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 

Similar to Laravel 4 package development (20)

Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
 
Phalcon 2 - PHP Brazil Conference
Phalcon 2 - PHP Brazil ConferencePhalcon 2 - PHP Brazil Conference
Phalcon 2 - PHP Brazil Conference
 
Phalcon - Giant Killer
Phalcon - Giant KillerPhalcon - Giant Killer
Phalcon - Giant Killer
 
PHP Conference - Phalcon hands-on
PHP Conference - Phalcon hands-onPHP Conference - Phalcon hands-on
PHP Conference - Phalcon hands-on
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
How to install laravel framework in windows
How to install laravel framework in windowsHow to install laravel framework in windows
How to install laravel framework in windows
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
Laravel and artisan cli
Laravel and artisan cliLaravel and artisan cli
Laravel and artisan cli
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A GrzesikApache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
 
Getting started with laravel
Getting started with laravelGetting started with laravel
Getting started with laravel
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
Dockerize Laravel Application
Dockerize Laravel ApplicationDockerize Laravel Application
Dockerize Laravel Application
 
Lumen
LumenLumen
Lumen
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 
Laravel Code Generators and Packages
Laravel Code Generators and PackagesLaravel Code Generators and Packages
Laravel Code Generators and Packages
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
معرفی و ساخت یک فریم‌ورک شخصی به کمک لاراول
معرفی و ساخت یک فریم‌ورک شخصی به کمک لاراولمعرفی و ساخت یک فریم‌ورک شخصی به کمک لاراول
معرفی و ساخت یک فریم‌ورک شخصی به کمک لاراول
 

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Laravel 4 package development

  • 2. THE PHP FRAMEWORK FOR WEB ARTISANS. ABOUT LARAVEL 4 RESTful Routing Beautiful Templating Proven Foundation Great Community Command Your Data Ready For Tomorrow Composer Powered Red, Green, Refactor
  • 3. HISTORY •CodeIgniter > Sparks •FuelPHP > Cells •Laravel > Bundles •CakePHP > The Bakery •ZF2 > Modules •RubyGems •NodeJS Package Manager •PEAR •PEAR2 PACKAGES PEAR PHP INSPIRATION
  • 4. Got a good PHP class? Is it only on GitHub, or maybe it's just sitting around on your blog? Stop that. Stop that right now. Make it into a Composer package and host it on Packagist. HISTORY ” http://philsturgeon.co.uk/blog/2012/03/packages-the-way-forward-for-php (*Phil Sturgeon: Pyro CMS)
  • 5. Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you. COMPOSER http://getcomposer.org/
  • 6. Packagist is the main Composer repository. It aggregates all sorts of PHP packages that are installable with Composer. PACKAGIST https://packagist.org/
  • 7. 1 2 3 4 CODE REUSABILITY MODULAR APPS OPENSOURCE LEVEREGE FRAMEWORK DEV MADE EASIER BENEFITS Main benefits while using Composer and Packagist to get or publish PHP Packages.
  • 8. 2012-04 2012-09 2013-02 2013-08 950000020000001000000100000 PACKAGES INSTALLED Source: https://packagist.org/statistics
  • 9. 1 2 3 4 INTRODUCED IN V.4 WERE BUNDLES IN V.3 FRAMEWORK GROWTH BOOST ENTIRELY MADE OF PACKAGES WORKBENCH PACKAGE DEV TOOL LARAVEL 4 Packages in Laravel 4 PHP Framework
  • 11. COMPOSER.JSON { "name": "orangehill/zgphpcon2013", "description": "Laravel 4 workbench package generation walkthrough.", "authors": [ { "name": "Tihomir Opacic", "email": "tihomir.opacic@orangehilldev.com" } ], "require": { "php": ">=5.3.0", "illuminate/support": "4.0.x" }, "autoload": { "psr-0": { "OrangehillZgphpcon2013": "src/" } }, "minimum-stability": "dev" } VENDOR / NAME DESCRIPTION AUTHORS DEPENDENCY PSR-0 AUTOLOADING INFO more: http://www.sitepoint.com/autoloading-and-the-psr-0-standard/ 
  • 12. Also Available in Serbian: Razvoj web aplikacija uz pomoć Laravel radnog okvira verzije 4 za početnike Slaviša Petrović  @slawisha75 CODEBRIGHT Dayle Rees @daylerees https://leanpub.com/codebright-sr https://leanpub.com/codebright
  • 13. COMPOSER.JSON $ php composer.phar install *phar: PHP Archive - entire PHP applications in a single file $ composer install *If you did a global install and do not have the phar in that directory run this instead
  • 16. Edit /app/config/workbench.php and set your name and email. This info is used later to populate the composer.json file. PACKAGE GENERATION Laravel Workbench Walkthrough 1 Edit workbench config file
  • 17. Use Command Line Interface (CLI) to navigate to Laravel 4 root folder, and then run: Note that orangehill represents a vendor (company name, personal name etc.), and walkthrough represents a package name. PACKAGE GENERATION Laravel Workbench Walkthrough 2 Run CLI (Command Line Interface) command php artisan workbench orangehill/walkthrough --resources
  • 18. Use your CLI to navigate to /workbench/orangehill/walkthrough and verify that the package structure has been created. PACKAGE GENERATION Laravel Workbench Walkthrough 3 Navigate to package directory
  • 19. Open /app/config/app.php to add a Service Provider to the end of the providers array: PACKAGE SETUP Laravel Workbench Walkthrough 4 Add a Service Provider 'providers' => array( // -- 'OrangehillWalkthroughWalkthroughServiceProvider', ),
  • 20. To create a main package class generate the file named Walkthrough.php inside a path /workbench/orangehill/walkthrough/ src/Orangehill/Walkthrough/ with the following code inside: PACKAGE SETUP Laravel Workbench Walkthrough 5 Create Main Package Class <?php namespace OrangehillWalkthrough; class Walkthrough { public static function hello(){ return "What's up Zagreb!"; } }
  • 21. Edit the Package Service Provider file /workbench/orangehill/ walkthrough/src/Orangehill/Walkthrough/ WalkthroughServiceProvider.php and make sure that the register method looks like this: PACKAGE SETUP Laravel Workbench Walkthrough 6 Register the new class with the Laravel’s IoC Container public function register() { $this->app['walkthrough'] = $this->app->share(function($app) { return new Walkthrough; }); }
  • 22. Note: If your service provider cannot be found, run the php artisan dump-autoload command from your application's root directory. PACKAGE SETUP Laravel Workbench Walkthrough 6 NOTE!
  • 23. Although generating a facade is not necessary, Facade allows you to do something like this: FACADE GENERATION Laravel Workbench Walkthrough echo Walkthrough::hello();
  • 24. Create a folder named Facades under following path /workbench/ orangehill/walkthrough/src/Orangehill/Walkthrough/ FACADE GENERATION Laravel Workbench Walkthrough 7 Create a Facades folder
  • 25. Inside the Facades folder create a file named Walkthrough.php with the following content: PACKAGE SETUP Laravel Workbench Walkthrough 8 Create a Facade class <?php namespace OrangehillWalkthroughFacades; use IlluminateSupportFacadesFacade; class Walkthrough extends Facade { protected static function getFacadeAccessor() { return 'walkthrough'; } }
  • 26. Add the following to the register method of your Service Provider file: This allows the facade to work without the adding it to the Alias array in app/config/app.php PACKAGE SETUP Laravel Workbench Walkthrough 9 Edit a register method of your Service Provider file $this->app->booting(function() { $loader = IlluminateFoundation AliasLoader::getInstance(); $loader->alias('Walkthrough', 'OrangehillWalkthrough FacadesWalkthrough'); });
  • 27. Edit your /app/routes.php file and add a route to test if a package works: BROWSER TEST Laravel Workbench Walkthrough 10 Edit a routes file Route::get('/hello', function(){ echo Walkthrough::hello(); });
  • 28. If all went well you should see the output in your browser after visiting the test URL: BROWSER TEST Laravel Workbench Walkthrough What's up Zagreb!
  • 29. First, let's modify the /workbench/orangehill/walkthrough/src/ Orangehill/Walkthrough/Walkthrough.php file to accept an optional parameter and echo out a message that we can observe in our CLI: ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 11 Modify a main package class public static function hello($verb = 'up'){ if (PHP_SAPI == 'cli') echo "What's $verb Zagreb?n"; return "What's up Zagreb?"; }
  • 30. Create a file WalkthroughCommand.php inside /workbench/ orangehill/walkthrough/src/Orangehill/Walkthrough/ folder with following content (code is pretty much self-explanatory): ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 12 Create a Command class <?php namespace OrangehillWalkthrough; use IlluminateConsoleCommand; use SymfonyComponentConsoleInputInputOption; use SymfonyComponentConsoleInputInputArgument; class WalkthroughCommand extends Command {
  • 31. ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 12 Create a Command class /** * The console command name. * * @var string */ protected $name = 'walkthrough'; /** * The console command description. * * @var string */ protected $description = 'Run the Walkthrough Package hello() method from command line.';
  • 32. ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 12 Create a Command class /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); }
  • 33. ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 12 Create a Command class /** * Execute the console command. * * @return void */ public function fire() { app('walkthrough')->hello($this->argument('verb')); }
  • 34. ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 12 Create a Command class /** * Get the console command arguments. * * @return array */ protected function getArguments() { return array( array('verb', InputArgument::REQUIRED, 'verb'), ); } }
  • 35. Modify Service Provider file register method to include the following code: ARTISAN CLI SUPPORT Laravel Workbench Walkthrough 13 Modify Service Provider file register method $this->app['command.walkthrough'] = $this->app- >share(function($app) { return new WalkthroughCommand; }); $this->commands('command.walkthrough');
  • 36. Run the test from CLI in your project root folder: CLI TEST Laravel Workbench Walkthrough 14 Run a test from CLI php artisan walkthrough cooking
  • 37. If all went well: CLI TEST Laravel Workbench Walkthrough What's cooking Zagreb!
  • 38. •Time/Date Management Classes •Various API Wrapper Classes •PDF Creation Libraries •Image Manipulation Libraries PACKAGES FRAMEWORK AGNOSTIC PACKAGES
  • 39. PACKAGES Satis - Package Repository Generator https://github.com/composer/satis PRIVATE REPOSITORIES
  • 40. Orange Hill Djordja Stanojevica 9b, 11000 Belgrade, Serbia MAP CONTACT US WWW.ORANGEHILLDEV.COM OFFICE@ORANGEHILLDEV.COM +381.64.167.7367