Can bundles be generated via app/console with sylius? - php

Learning Symfony2 and Sylius at the same time here. Thanks for your patience.
What brought me to this question is the desire to override some of Sylius's default functionally. The first of which I am focusing on is tax behavior. I want to accommodate specific tax rates for several different on the ground stores. As I understand it, if I want to be able to update future changes in Sylius, I don't want to modify code in sylius/src/Sylus/* correct? I think I understand how to make the overrides, but I cannot seem to generate my own bundle with Sylius.
ubuntu#ubuntu-VirtualBox:/var/www/sylius$ php app/console generate:bundle
[InvalidArgumentException]
Command "generate:bundle" is not defined.
I can run the same command in a generic Symfony2 install I have, and it works.
Am I doing something wrong / something is broken, or has bundle generation been removed from Sylius and it is expected that bundles be written all manually?
Thanks, and any links to further reading on this are appreciated.

You need to install SensioGeneratorBundle if you want this feature. This bundle is not included in standard Sylius distribution. Installation and their usage is pretty straightforward ;)
Yup, I think you shouldn't edit core bundles but instead override whatever you want - see here how to achieve that. Sylius is built with good design so overriding could be easily achieved by simply having your own DI class parameter instead of core class.
Cheers!

Related

Symfony 2 reusable bundles

Let's say I want to create a Blog in Symfony which lives in BlogBundle. But this BlogBundle has dependencies on other bundles like FOSUserBundle, KnpPaginator bundle, FMBbCodeBundle or whatever I end up using. Does this mean I can't really reuse the BlogBundle in another project. The Best Practices for Reusable Bundles chapter of the symfony cookbook says
A bundle must not embed third-party PHP libraries. It should rely on the standard Symfony autoloading instead.
But what does that mean exactly? Can't I use anything that isn't programmed by me?
If that is the case, I'd have to reinvent the wheel for the most basic problems I encounter in developing my bundle. For example I would have to come up with my own paginator to paginate content, create my own user manager and so on..
I don't see a point in that as I would waste my time fixing problems that have already been done much better than I could do.
Or does the cookbook mean I can't use anything that doesn't live inside a bundle. This would make much more sense to me.
It really irritates me that nobody really has done a blogbundle or something similar that gets good feedback and is mentioned anywhere in the top lists. I know, Symfony isn't meant to have a solution that just works out of the box and some coding is necessary, but still. All the bundles I can find that seem to be very popular are the ones that do something like parse BB Code, take care of User Management and other things that are hard and tedious to do, but never something bigger than doing only one task.
I hope you understand what I mean and can help me with my problem. Thanks in advance!
A bundle must not embed third-party PHP libraries. It should rely on
the standard Symfony autoloading instead.
This means that you shouldn't copy code of other libraries to your Bundle (directory). Instead that you should add them as a dependencies to your composer.json.

Update Laravel main app directory

Is there an easy way to incorporate changes to the main Laravel app, when there are framework updates, other than manually incorporating the changes described in the documentation (http://laravel.com/docs/5.1/upgrade)?
I'm thinking some kind of composer command that patches the main app and not only the vendor dir. Does such a thing exist?
Thanks in advance.
Apparently, Shift is exactly what you're looking for, although it's still in its alpha. You can contact its creator if you want to help him test the tool.
Reference: http://jason.pureconcepts.net/2015/11/laravel-automated-upgrade-tool-shift/

Is there a "plug and play" approach for Laravel modules?

I have a question, I am still getting to grips with Laravel (came over from CI)
I'm looking to implement modules into my application in a similar style to say, wordpress plugins. I took a look at some of the HMVC libraries available but they all seem to require you to explicitly declare each service in the app/config/app.php
I'm wondering if there's a more plug and play approach I can take, where I am able to drop in a folder and it works off the bat, is there an appropriate way to implement this?
Thanks
I don't think there's a "drop in folder and it just works" solution for Laravel, but Packages is probably the closest to what you are describing:
http://laravel.com/docs/packages
Usually after you install a package, you run an artisan command to publish configurations and potentially run some database migrations, and then you're good to go.
I would start there if you want to create some additional self-contained functionality without wading into the existing site..
I've written a Laravel 5 package that manages modules. You can "drop in folder and it just works".
There is also a artisan module generator.
l5-modular have fun, save some time ;)

How should I structure my application?

I understand that this question may be vague, I will try my best to explain my problem and hopefully can get lots of insights from the experienced and hopefully this will not be closed.
I'm writing a PHP web app framework based on Symfony 2's components and bundles, my question may not relate to that however. The framework is intended to be open to 3rd party plugins, these plugins will have their own config files (yaml) and the person who install these plugins should be able to override these settings locally.
I also have to make sure that each time the person perform the plugin upgrade operation, it should be easy to loop over the list of "upgrade patches" to upgrade the plugin's settings while still retaining the local settings.
I imagine I can have a local, app's specific plugins.yml file which store something like this:
pluginA:
somesettings: value
somesettings2: value2
This app's specific settings file will allow user to override any default settings. And then each plugin can contain an "upgrade" class that will contain all the patches for each version, the framework will identify the current installed path and will loop through each "upgrade patch" and perform actions until it reach the most current version.
Does this sound like a good option, or if there is something else I should look into? How do I have configuration settings that can be overridden can be upgraded easily? Please let me know if you need more details.
It seems to me that you are looking to achieve something that actually core Symfony allows to do - i. e. to let other users override / implement custom parts of an already existing bundle.
If so, maybe this answer can give a good idea on how to achieve that using the ClassLoader Component (Symfony 2.0) or Composer (Symfony 2.1):
How can I override Core Symfony2 Classes?

In Symfony2 where do I put e.g. TCPDF?

I'm on Symfony 2.0 and understood that third-party libraries go in /vendor. I have two third party classes I'm using, one is TCPDF and another is a Paypal class. Neither have formal Symfony2 Bundles.
So I followed the instructions here which namespaces them and makes them usable inside /vendor:
Add third party libraries to Symfony 2
This works and I can access them from my Controllers. However I'm rethinking if that's the right thing. Whenever I do..
php bin/vendors install --reinstall
..those custom classes disappear because they don't have a Git repo in 'deps'. This has caused real problems e.g. when trying to deploy on e.g. PagodaBox. I get the strong instinct that this code while 'third-party' belongs closer to the code of my app.
If that's true, should it:
Sit next to my Controllers in src/MyCompany/MyBundle/Controller/tcpdf.php
Be with my other custom-written services in src/MyCompany/MyBundle/DependencyInjection/tcpdf.php
Go in its own directory under my bundle: src/MyCompany/MyBundle/TCPDF/tcpdf.php
If I move these two classes from /vendor to one of the above, would I access it from a Controller with a 'use' statement, or would I need to define it in 'services.yml'?
I hope this isn't so much a matter of discussion or opinion but some guidance I've missed or best practise I'm unaware of that a more experienced Symfony2 dev would know.
Would it be sensible to switch to Composer even before Symfony 2.1 is ready?
Thanks for reading.
If you're using deps to manage vendor libraries then you should add the git repo's for those libraries there.
For TCPDF you can use:
[TCPDF]
git=git://tcpdf.git.sourceforge.net/gitroot/tcpdf/tcpdf
target=/tcpdf
If you have other libraries that aren't in a public repo then you may want to commit them to your own repo.
The same would hold true for Composer. Just the syntax for adding non-packagist repo's is different.

Categories