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

Vanilla PHP

Vanilla PHP

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

Tomasz Kowalczyk

March 16, 2015
Tweet

More Decks by Tomasz Kowalczyk

Other Decks in Programming

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. 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
  4. Next steps? → scaffolding → bundles → controllers → modules

    → repositories → entities → views → templates → configuration → services → libraries → dependencies → tests → environment → forms → ...
  5. 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
  6. 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
  7. 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
  8. 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);
  9. → 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?
  10. → 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