0

I'm a Laravel (PHP) developer, and new with DI, Packages (workbench) and Repositories (Pattern).

I want to know about the best concept/methodology for a more flexible design; ie. the project can grow and become something very modular.

For example, after watching some Jeffrey Way videos in Laracasts I decide use that pattern:

  • app/
  • app/config
  • app/controllers
  • app/database
  • app/views
  • app/patrickmaciel (psr-4 in composer.json)
  • app/patrickmaciel/user (repositories, eloquent model, validation, etc)
  • app/patrickmaciel/group
  • app/patrickmaciel/post
  • app/patrickmaciel/billing
  • app/patrickmaciel/helpers
  • app/patrickmaciel/filters

But after watch more videos, and reading more about flexibility, I see developers using packages instead of this psr-4 alternative (composer.json):

"require": {
    "patrickmaciel/group",
    "patrickmaciel/user",
    "patrickmaciel/post",
    "patrickmaciel/billing",
    "patrickmaciel/helpers",
    "patrickmaciel/filters"
}

So, what is better for more flexibility?

2

The first solution you have proposed is an excellent solution, as it namespaces your code properly and means that your code is in the correct structure should you want to shared your code through a package manager (like packagist) later on.

If, at some point, you intend to share you code to other developers via something like packagist, you would do the nexessary work to package it and then others could import your code using the require block you've noted second. If the code does not need to be shared publicly then I don't think the second approach provides any benefits.

  • Thanks for you answer my friend. And yes, I think namespaces looks better in this case too. – Patrick Maciel Nov 18 '14 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.