Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
Examples of Dependency Injection in PHP With Symfony Components
Aug 08, 2018 @ 16:53:33

On the TutsPlus.com site today they've posted a tutorial sharing some examples of dependency injection using the Symfony DependencyInjection component.

In this article, we'll look at some examples of using the Symfony DependencyInjection component. You'll learn the basics of dependency injection, which allows cleaner and more modular code, and you'll see how to use it in your PHP application with the Symfony component.

The tutorial starts by introducing the component and what kind of functionality it includes to help register and fetch services on demand. It then walks through the installation (via Composer) and the installation of other optional related packages. It then dives into the code, showing how to put the package to use to register a new service and pull it back out to use. The article then moves on and shows a more "real world" example with services that have dependencies and configuring it in a YAML configuration file.

tagged: dependency injection tutorial symfony component introduction dependencies

Link: https://code.tutsplus.com/tutorials/examples-of-dependency-injection-in-php-with-symfony-components--cms-31293

BitExpert Blog:
Enforce software layer dependencies with deptrac
Aug 19, 2016 @ 15:54:24

On the BitExpert.de blog there's a new post from Stephan Hochdörfer covering the enforcement of software layer dependencies with the help of the deptrac tool from Sensiolabs.

Deptrac is a tool recently announced by Sensionlabs. It helps you keep dependencies between the different layers in your architecture under better control by providing insight into the current state of the dependencies and warns you when unwanted dependencies get introduced.

He gives the commands to get the tool installed and how to initialize the repository with a default configuration file. He then provides an example using the Adrenaline framework and how the request/response relate to the HTTP handling. He includes the configuration changes to make for these relationships and, finally, how to run the analysis on your code to ensure the dependencies are correct.

tagged: software layer dependencies deptrac sensiolabs

Link: https://blog.bitexpert.de/blog/enforce-software-layer-dependencies-with-deptrac/

Marc Morera:
You Probably Need Bundle Dependencies
Feb 10, 2016 @ 15:04:18

In this post to his site Marc Morera responds to some comments from another post about bundles dependencies in Symfony-based applications.

This post tries to answer the Magnus Nordlander’s blog post, and to explain why the Symfony Bundle Dependencies is not just a personal project to fulfill my bundles dependencies, but a practice we should implement in all our Symfony bundles as well.

Believe me, I had a big post to explain why people really need this bundle, but I think that you don’t need these words, but a simple and real example.

He points out a more "real world" example of why this kind of dependency system can be useful in Symfony development. He points out a common service (security.encoder_factory) that's used widely across many bundles, but also defined as a dependency in each. If the bundle dependency structure/tool was in wide use, this dependency would be define elsewhere and not as a part of the bundle itself.

tagged: bundle dependencies symfony security factory example

Link: http://mmoreram.com/blog/2016/02/09/you-probably-need-bundle-dependencies/

Marc Morera:
Your Packages Dependencies
Dec 04, 2015 @ 16:36:58

In a recent post to his site Marc Morera discusses the topic of package dependencies in PHP applications. While a lot of the concepts and terms he use are more related to Symfony-based applications, the concepts are good and could apply anywhere.

I’m part of this group of people that consider themselves addicts to open source. [...] want to expose my personal experiences about what I learned over the time by leading an open source project, several small open source bundles and PHP libraries, and I want to do it by explaining how we should take care of our Symfony bundles or PHP component dependencies.

He starts by pointing out that he's talking about framework-agnostic packages and their dependencies here (but his own experience is, again, Symfony-centric). He talks about identifying true dependencies through both use statements and composer.json configurations. He points out that the tricky part comes when your dependencies have dependencies and conflicts that may come up because of these relationships. He also talks about another way to identify dependencies (through adapter use) and package versioning problems. He then gets into talking about Symfony bundle dependencies specifically and links to a tool that can help you map out your required packages. He ends the post with a look at development dependencies and the idea of "trust" in the open source software you use.

tagged: package dependencies version use composer adapter symfony bundle trust

Link: http://mmoreram.com/blog/2015/11/20/your-packages-dependencies/

Marc Morera:
Composer Install in CI
Sep 29, 2015 @ 15:48:38

In this post to his site Marc Morera talks about Composer dependencies and an issue that can come up with two things: having a large number of dependencies and minimum PHP version requirements (and when they change).

Any final project needs a lot of dependencies, and even if your composer.json file is small, you may need a dependency with a lot of dependencies. [...] Computing the real dependencies in my environment seems a great solution, right? I run composer update in my computer, I update the composer.lock version in the repository, and then I only need to do composer install. What I reduce here is the computing time of all recursive dependencies from 20+ minutes to less than 5 minutes. [...] Why this is a bad solution?

He explains that some projects will change the PHP version requirement in a minor version, potentially causing your build to break on other versions without you changing anything. He points out that there's "no good solution" he sees but does recommend good upkeep of your composer.json as a composer update is the best course of action. He also makes recommendations to the library developers about keeping requirements scope as wide as possible and only defining specifics when the project is finalized.

tagged: composer install continuous integration update dependencies

Link: http://mmoreram.com/blog/2015/09/28/composer-install-in-ci/

Marc Aube:
Choosing your project's dependencies
Jun 02, 2015 @ 16:01:59

Marc Aube has shared some thoughts about picking your project's dependencies and considerations to think about when building your applications.

If you work on any non-trivial project, chances are you'll install one or many external dependencies at some point. [...] However, you shouldn't bring any library in your codebase. While Packagist has, at the time of writing, around 60000 packages you could use in your project, most of them are not production quality. Here's a list of things to look for when choosing a generic library for a mission-critical project, in no particular order.

Among the things he suggests, there's tips like:

  • Ensure it has a stable version
  • That it's extensible
  • It's active and maintained
  • The license permits the intended use
  • It has quality documentation

For each he offers a brief paragraph or two explaining the point and examples where appropriate of projects matching the topic.

tagged: dependencies project opinion list suggestion choice

Link: http://marcaube.ca/2015/06/choosing-dependencies/

Scotch.io:
A Beginner’s Guide To Composer
Mar 31, 2015 @ 18:48:55

The Scotch.io site has posted a guide that can help you if you're just getting started in the world of PHP packages via Composer. In this new tutorial Daniel Pataki introduces you to the tool and how to use it to install the dependencies you need.

I’m sure there are plenty of coders out there who are wondering about the benefits of using composer and many who are afraid to make the leap into a new system. In this article we’ll take a look at what exactly Composer is, what it does and why it is a great tool for PHP projects.

He starts with the basics of dependency management, why it would be used in a project and how it automates the installation and integration of 3rd party libraries. From there he helps you get Composer installed and starts in on a sample "composer.json" configuration file. In his example he installs Monolog, the popular PHP logging class. He talks some about how to specify versions, locking down the dependency versions to install and installing "developer only" requirements.

tagged: composer package dependencies library introduction beginner guide

Link: https://scotch.io/tutorials/a-beginners-guide-to-composer

VG Tech Blog:
Using Local Packages as Composer Dependencies
Nov 25, 2014 @ 15:16:45

On the VG Tech blog this latest post shows you how to use local packages as dependencies in your Composer-enabled applications.

Composer changed pretty much everything when it comes to including dependencies in PHP projects. No more SVN externals or copying large library folders into your project. This is really great, but there’s one thing I’ve been struggling to find a smooth process for; developing dependencies for your project. When implementing your project, the need for some module, library, service provider or something else will arise, and sometimes you’ll have to implement it yourself. So, how to do that?

He starts with a list of three suggestions (including actually having the code in the project or mirroring the package) but suggests the last of the three: using a repository with a relative file system setup. He uses the "repositories" configuration option in the Composer config to define a "vcs" type and gives it a path to the package contents. He ends the post with the resulting output of the Composer install command, showing the package pulled in and being able to commit to it just like any other repo.

tagged: local package composer dependencies tutorial repository

Link: http://tech.vg.no/2014/11/25/using-local-packages-as-composer-dependencies/

NetTuts.com:
Refactoring Legacy Code: Part 8 - Inverting Dependencies for a Clean Architecture
Jul 10, 2014 @ 16:04:13

NetTuts.com has posted part eight in their series looking at refactoring legacy code - Inverting Dependencies for a Clean Architecture. In this latest post they move away from just refactoring the code and start to look more at fixing the architecture of the application.

Old code. Ugly code. Complicated code. Spaghetti code. Gibberish nonsense. In two words, Legacy Code. This is a series that will help you work and deal with it. It's now time to talk about architecture and how we organize our newly found layers of code. It's time to take our application and try to map it to theoretical architectural design.

They look at the current structure of the code (well, of their refactored version) and how to apply the Dependency Inversion Principle (part of the SOLID methodology) via interfaces. The code is included for the refactor as well as tests to add to their "Golden Master" test suite to ensure continued correct functionality.

tagged: refactor legacy code series part8 inverting dependencies

Link: http://code.tutsplus.com/tutorials/refactoring-legacy-code-part-8-inverting-dependencies-for-a-clean-architecture--cms-21659

Master Zend Framework:
Howto Handle External Form Element Dependencies with FormElementManager
Apr 22, 2014 @ 16:58:07

The Master Zend Framework site has posted a tutorial wanting to help you understand external form element dependencies with help from FormElementManager.

Zend Framework 2, like all great PHP frameworks, provides thorough infrastructure for creating forms in your application. Whether that’s form objects, form elements, fieldsets, validation groups or that they interact with so many other components in the Zend Framework 2 default libraries. But how do you handle external dependencies? [...] So what if you need a custom form element in your application, one which will render a list of articles from a database table? [...] In today’s post, we’re going to look at how to create such a custom element, extending the existing select element.

He walks you through the steps you'll need to make the custom element and hook it into the FormElementManager for correct use:

  • Create a New Form Element
  • Implement the getFormElementConfig Method
  • Create a New Form Object
  • Instantiate the Form Via the FormElementManager

Code is included for each step of the way so you can ensure you end up with a working example.

tagged: external form manager element dependencies external tutorial

Link: http://www.masterzendframework.com/zend-form/handle-external-form-element-dependencies-with-formelementmanager


Trending Topics: