Symfony 3.3 - where does assets:install look for web assets? - symfony

Back in Symfony 2.x, the assets:install command looked for assets in /path/to/YourProject/YourBundle/src/Resources/public and copied (or symlinked, depending on whether or not the flag was used) those files to /web. Now that assets are stored in /path/to/YourProject/app/Resources in Symfony 3+, does the console command look there instead? Should I even bother using that console command at all?

According to the recent symfony best practice store your assets directly in web folder. Check this out: https://symfony.com/doc/current/best_practices/web-assets.html
This way your assets will be available without touching server-side commands. Also any frontend developer working on your project does not need to know anything about symfony, he will work directly with assets in web folder and templates in app/Resources/views

Related

Use third party composer packages in TYPO3 extensions

I have integrated a Service Worker for receiving Push Notifications in my TYPO3 Extension.
Now I want so send Messages form backend to the clients web-push-php Library.
But how it is possible to integrate the library and its dependencies to TYPO3?
If you set up your project with composer you can just require minishlink/web-push and start using class Minishlink\WebPush\WebPush.
In case you‘re running in "legacy" mode (i.e. classic install without composer) or want to support both you‘ll need a different approach. IMO best practice is bundling composer requirements in .phar files - this way you can keep your IDE clean and your VCS footprint small. There‘s a blog post with a detailed description about phar bundling in TYPO3 extensions.
This method works for most composer requirements following PSR-0 or PSR-4 and should be viable in your case as minishlink/web-push seems to follow PSR-4.
You can even advance this by using scripts you can launch by running composer run <script> in your extension‘s root folder. TYPO3 extension typo3_console holds a composer.json defining such scripts.
If you need to run your extension in a TYPO3 6.2 environment you‘ll need to remove composer.json from extension folder as 6.2 fails coping with "real composer requirements" (i.e. non-TYPO3-extension packages).

Symfony : Why put assets in web/ diectory instead of bundle's Resources/public/?

I always thought symfony is one of the best PHP Framework because it uses bundles : all files are grouped in the bundle folder : views, controller, assets, so I can create severals web sites with one symfony installation (like Wordpress Multi-site) ... But I found this in the official documentation :
Best Practice : Store your assets in the web/ directory.
It means files are no more grouped ! Can some one explain me what are the advantages ?
I also read Sensio will perhaps no longer use bundles !! Why ???
If the assets are bundle specific, you can use then under the bundle. web directory is the end-user facing root and referencing assets in an website / API from your bundle to the end-user is not suggested from security point of view.
So, even if you have your assets under Resources/public/ directory. You have to run the command asset:install to install those assets to web/bundles directory. This will help the bundle to make compatible with plug and play feature across the application.

How to keep a Symfony2 symlink when transfer to ftp

I have a Symfony2 project, and I was wondering how to use assetics which are located in the bundle folder in the view. So I searched the web to find a solution, and I found this command :
php app/console assets:install web
And it works fine on my computer. It created a symlink (seen as a shortcut on windows) so I can call my assets just with something like :
asset("bundles/mybundle/folder/file.css")
But everything changed when... I uploaded it.
The symlink became an actual folder with a copy of all the content of the public folder from my bundle. So when I made changes on src/my/bundle/resources/public/folder/file.css, it didn't change web/resources/bundles/mybundle/folder/file.css because it was a copy, and not a shortcut.
How can I keep a symlink ? Is it because I'm on windows and my server is on Linux ?
The symfony2 standard way is to have a copy of all js and css files in your web directory.
Think of it as a clean separation between user/client accessed files and strict server side files. You can workaround it, but you shouldn't.
To solve your problem, after each update to your server you have to delete all files in web/resources/bundles (to make sure removed files from your bundle are not present anymore) and rerun
php app/console assets:install web

Release Symfony2 project to the web

I have almost finished the development of a project developed with Symfony2, and wish to put the project online.
However, I suppose there are a lot of things that need to be done so that everything works ok. I suppose, the dev mode needs to be disabled etc....What needs to be done and how?
What are the most important things to do on a Symfony2 project that will be available to everyone on the web?
I suggest you to use Capifony for deployment. It does a lot of stuff out of the box and you can make it run any custom commands you need. See its documentation for details.
Regarding the dev mode, unless you've removed the IP checks from app_dev.php, you don't have to worry about deploying it. Of course, if you wish, you can tell Capifony to delete it on deployment.
The best way to handle deployment is to create "build" script, which will:
Remove all folders and files with tests from your bundles and vendors.
Remove app_dev.php file
Make sure that app/cache and app/logs are fully writable/readable.
Packs your project into archive (rpm f.e.)
Then, before deployment, you should create tag in your project - so it will mean, that certain version of your application is released (I recommend to follow this git branching model).
Create tag.
Run your build script
Upload archive to host
Unpack
Enjoy your project
Im currently researching the same thing.
The first thing you have to consider is "how professional" you want to deploy. There are a lot of tools you can use:
Continous Integration Server ( e.g. Hudson, Jenkins)
Build Tools (e.g. Phing, Capistrano --> Capifony, Shell scripts)
Versioning Tools (e.g. Git, SVN)
I think the simplest setup is using only a Build tool and i guess you are already using some kind of versioning.
Depending on which tool you use, the setup is different, but I think there are some things you should consider with your application (maybe not all are applicable to your application)
Creating a Tag in your Versioning
Copying the new Code in an folder on production
--> if you are in a new folder you dont need to clear the cache and logs, since these shouldnt be in your versioning the first time.
loading composer (if youre using it)
installing vendors
updating database schema
install assets from your bundles
move symlink from current version to the folder of the new site
These are the things I currently need for my application for production deployment, if you deploy to an test environment you should load fixtures and run your testscripts as well.
One other option that is very well described here is to deploy the Symfony2 application with Apache Ant. Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other.

Symfony 2 - Working with assets

I need some tips on how to work with assets in Symfony 2. For example, do we have to always perform the assets:update every time an image is added ? I know Assetic take care of the management on css and javascript files but what about images? What would be the best practice for the front-end development with Symfony 2 ? How do you guys setup your css, images and js files in your app to make it easy to develop, deploy and change ?
Regarding images, if you added it into your public folder, I think there's no need to perform assets:update
However, if you add the image within the resources folders of a bundle, you might have to, depending on your OS and which options you used when called assets:install
If you're using an OS which supports symlinks (linux, OS X, and I guess all OS but Windows), you can install the assets calling (I don't exactly remember the call, the important thing here is the symlink option):
php app/console assets:install web --symlink
This way, instead of having a copy of each bundle's resources, you'll have a symlink, so there should be no need to update. If you have an OS which doesn't support symlinks, I think you'll have to keep updating or reinstalling assets (in fact, I always used assets:install, I didn't knew there was an update option :P).
Regarding the set up, I usually put all css, js, images and any public resources inside a bundle if it is used only within the bundle, and place it onto the public folder if it's used by many bundles, or I plan to use it in other bundles.
As of Symfony 2.7 this will generate relative symlinks in web directory:
php app/console assets:install web --symlink --relative
In composer.json add:
"extra": {
"symfony-assets-install": "relative"
}
This will also generate relative symlinks on composer update.
Here is cool think about --symlink.You can configure(config) one time and use forever.If you want more http://www.w3docs.com/snippets/symfony/how-to-keep-symlinks-in-web-bundles-after-composer-update.html

Resources