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

Package Development PHP Antwerp

Package Development PHP Antwerp

Intermediate and advanced tips for PHP package development. Laracon EU try-out.

Rates on https://joind.in/14996

Hannes Van De Vreken

August 18, 2015
Tweet

More Decks by Hannes Van De Vreken

Other Decks in Technology

Transcript

  1. BEGINNER STEPS - VERSIONS /** * Register method. */ public

    function register() { // Register SDK class. $this->app->singleton('twilio', function () { $config = $this->app['config']; return new Sdk($config['services.twilio']); }); }
  2. BEGINNER STEPS - CODE STYLE $container = new Container; $container

    = new Container(); $options = [ 'ssl' => true, 'redirects' => false, ];
  3. BEGINNER STEPS - CHANGELOG # Change Log All notable changes

    to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] ### Changed - Improve argument against commit logs. ## [0.0.8] - 2015-02-17 ### Changed - Update year to match in every README example. - Reluctantly stop making fun of Brits only, since most of the world writes dates in a strange way. ### Fixed - Fix typos in recent README changes. - Update outdated unreleased diff link.
  4. BEGINNER STEPS - README.MD // open an image file $img

    = Image::make('public/foo.jpg'); // resize image instance $img->resize(320, 240); // insert a watermark $img->insert('public/watermark.png'); // save image in desired format $img->save('public/bar.jpg');
  5. BEGINNER STEPS - HINT 1 $ construct generate --help Arguments:

    name The vendor/project name Options: --test (-t) Testing framework (default: "phpunit") --license (-l) License (default: "MIT") --namespace (-s) Namespace for project (default: "Vendor\\Pro --git (-g) Initialize an empty Git repo --phpcs (-p) Generate a PHP Coding Standards Fixer config --keywords (-k) Comma separated list of Composer keywords --vagrant Generate a Vagrantfile
  6. BEGINNER STEPS - HINT 2 $ studio load --help Usage:

    load <path> Arguments: path The path where the package files are located
  7. INTERMEDIATE TIPS - ENVIRONMENTS - CI phpunit --coverage-html=/tmp/coverage/; vs phpunit

    --coverage-clover=/tmp/coverage.xml; ocular code-coverage:upload /tmp/coverage.xml;
  8. INTERMEDIATE TIPS - CLEAN DISTS "autoload": { "psr-4": { "GuzzleHttp\\":

    "src/" } }, "autoload-dev": { "psr-4": { "GuzzleHttp\\Stubs\\": "tests/stubs/" } }
  9. DECOUPLING - HTTP EXAMPLE /** * @param \Psr\Http\Message\RequestInterface $request *

    @return \Psr\Http\Message\ResponseInterface */ private function send(RequestInterface $request) { return $this->adapter->send($request); }
  10. DECOUPLING - HTTP EXAMPLE /** * @param \Http\Adapter\HttpAdapter $adapter */

    public function __construct(HttpAdapter $adapter) { $this->adapter = $adapter; }
  11. DECOUPLING - INTERFACES concept virtual package is a placeholder to

    be able to define a dependency on some implementation
  12. DECOUPLING - RECAP - Single responsibility - Try to decouple

    from implementation - Depend on virtual packages