Skip to content

Reusability Of Symfony Component - Mindworks

By Oliver
Mindworks
Jarrestraße 42A
Take a look to knpbundles.

Hurdles

  • problem is solved in other language
  • problem is solved in other licence
  • can be solved by design patterns (abstract solution)
  • write a good bundle/component that is general enough takes much more time

Anti-Pattern

Reuseage by copy and paste.

  • decreases maintainability
  • decreases testability
  • violates dry principle

Scenario

  • community web application
  • users seek other users by interests
  • how to input data to easy up matching?

What Do We Need?

  • form widget (js and css based)
  • data transformer (converts format from storage to human readable presentation and back)
  • form type (provides name for form widget, called in FormTypes, gets TagManager injected and defines DataTransformer)
  • Entity Trait (avoid copy and paste)
  • Taggable Subscriber
  • Make it reusable (dedicated bundle, created composer project)
  • Use JavaScript and CSS via "composer component" (see web/bundles, RobLoach/component-installer)

Live Demo

Available on github

current Software Components Available On Github And Packagist (Symfony Console Command, IO, Application and Configuration Format Converter)

After getting more and more into the great world of composer based systems, i tried to reuse code from my current and ongoing projects and cast them into separat components.

Right now, the follwing are available: - Symfony Console IO - Influenced by a teammate and by composer, i wanted to have IO object in my console applications. - Symfony Console Command - Since the IO component makes more sense in the command and since, again influenced by teammate and composer, i wanted to have a command code that stops me from repeating myself in different console applications. - Symfony Console Application - The last package from my lab, like the command, this package is a application with my flavor. - Component Configuration Converter - I was getting sick of converting configuration formats from one to another, so i create a component for that. Currently the following formats are available: - YAML - XML - JSON - PHPArray

All Packages are availalbe on github.com and i would be glad if you are going to test them in the real world and add some defects.

tool php classmap generator packagist

After a month, i've finished a tool to create a classmap from a php project. The current stable version is v1.4 and can be found on github.com as well as on packagist.org. Why? Well, obviously because i can (and wanted to learn a few things like tokens, or symfony console) ;-). But for real, when you have to deal with legacy projects or code but want to remove the strange and slow existing autoloader (with all its exception), the easiest way to do this is by using a classmap. I also tried to find a classmap generator that can deal with psr-0 and not psr-0 files, all i could find are generators that support psr-0 files. A classmap itself is just a php array. The key is the full qualified classname and the value is the relative path to the file. Creating a classmap on your own is suitable when you have to manage a number of files below 20. But when it comes to more you can not effort the time to maintain that file. So for a lot of files that are not covert by composer, the classmap generator should be well suitable. It is planned to implement a "phar" classmap generation for the upcoming version. When you want to create phar files, this could be a timesaver as well. The classmap generator is build by using symfony\console and yes, it is a joy to work with that component! Shame on me, the current version is not covered by unittests. After i implemented the current features from the todo list, this will be my major task.

The classmap generator can handle all kind of php files like: - Interface - Abstract Class - Class The generator can handle files with or without namespace. Even files with multiple definitions (interface, abstract class and class in one file) is no problem. Furthermore, you can create multiple configuration files and update this classmaps when needed. Like well known from the composer, the classmap generator is able to create a autoloader file for you. The created autoloader will use the created classmap file and supports psr-0 autoloading. source/link to the wiki

What is left to write? Of course i'm proud about this. What you see right now is the work of one month and after i finished the core design, i rebuild a lot by replacing my cli application class with the symfony\console component. I hope you can use the tool. If you need help or found a bug, contact me on github.com