Pro Yearly is on sale from $80 to $50! »

Vanilla PHP

Vanilla PHP

How not to let the ready-made solution trees hide the wood of possibilities behind them.

Bb29f6afb2ea244a12c25e04d46af19c?s=128

Tomasz Kowalczyk

March 16, 2015
Tweet

Transcript

  1. Vanilla PHP how not to let the solution trees hide

    the wood of possibilities behind them https://www.flickr.com/photos/ted_major/6600956129/ Tomasz Kowalczyk
  2. thunderer@THUNDER$ whoami PHP ~2007 Lead Engineer @ HASH.FM GitHub /thunderer

    Twitter @tmmx http://mientefuego.deviantart.com/art/Carbon-Glider-129268523
  3. None
  4. Brand new, shiny, greenfield project... $ composer create-project symfony/framework-standard-edition NAME

    $ composer create-project zendframework/skeleton-application NAME $ composer create-project yiisoft/yii2-app-basic NAME $ composer create-project cakephp/app NAME // ... $ composer create-project laravel/laravel NAME
  5. Next steps? → scaffolding → bundles → controllers → modules

    → repositories → entities → views → templates → configuration → services → libraries → dependencies → tests → environment → forms → ...
  6. how about some change?

  7. NOPE*! “one bad programmer can easily create two new jobs

    a year” * irony
  8. “ if it ain’t broke, don’t fix it ” -

    industry
  9. FDD: FRAMEWORK-DRIVEN DESIGN → hinders ability to change → vendor

    lock-in → domain coupled to framework → locks away job opportunities → “Rails programmer”-like titles → artificial walls between people → forced structure https://www.flickr.com/photos/binaryape/3625043250
  10. how can I change this?

  11. components

  12. look mOm, no framework! → Open Source projects “design pattern”

    → semantic versioning → modular, elastic and independent code → framework as an implementation detail → rewrite basic Symfony2 in less than 100 LOC → shorter and easier code means less bugs → use framework to build only “application” layer → code independent from changes in other projects
  13. Example project structure: ............... ................ ................. ................. ................. ............... .................

    ............. ................. ................. ................. ................. ................. ................. ............... ............. ................. ............... ................. .............. ........... ........ ..... /project /apps /web /etc /src /views /web /console /bin /cli /src /etc /lib /src /tests /uploads /var /cache /log /vendor .gitignore .travis.yml composer.json composer.lock phpunit.xml.dist project directory applications directory web application configuration web application source code web application views front controller console application application executable application executable source code console application source code project configuration domain code applications shared code unit tests user data (images, etc.) dynamic application data cache directory log directory dependencies dotfiles Composer files PHPUnit configuration
  14. How to rewrite Symfony2: $twig = new \Twig_Environment(new \Twig_Loader_Filesystem(array($templatesDir)), array('cache'

    => $cacheDir)); $twig->addExtension(new TranslationExtension($this->getTranslator())); $twig->addExtension(new FormExtension(new TwigRenderer(new TwigRendererEngine(array('form_div_layout.html.twig'))))); $assetFactory = new AssetFactory($assetsDir); $assetFactory->setAssetManager(new AssetManager()); $twig->addExtension(new AsseticExtension($assetFactory)); $loader = new YamlFileLoader(new FileLocator(array($routingDir))); $router = new Router($loader, $routingFile, array(), null); $session = new Session(new NativeSessionStorage()); $formFactory = Forms::createFormFactoryBuilder()->addExtension(new CoreExtension()) ->addExtension(new HttpFoundationExtension()) ->addExtension(new ValidatorExtension(Validation::createValidator())) ->getFormFactory(); $transport = \Swift_SmtpTransport::newInstance($this->host, $this->port, $this->security) ->setUsername($this->user) ->setPassword($this->password); $mailer = \Swift_Mailer::newInstance($transport);
  15. → on your skills → on your experience → on

    your approach → on your requirements → on your company → on your process → (...) of course “it all depends” but maybe those are only minor excuses?
  16. → strong experience or experienced leader required → you need

    to care about structure and quality yourself → no ready-made solutions → manual implementation of all new ideas → you cannot rely on your knowledge of given framework → you cannot hire based on some framework knowledge of course there are disadvantages
  17. COOL STORY

  18. askQuestions() or die();

  19. good code is not going to write itself... so... WE’RE

    HIRING! (YAY!) wait for it...
  20. Thanks! (thanks for all your input!)