moving bundle from vendor to src directory - php

I installed SonataMedia in the vendor/ directory of my project using composer and everything was working fine. I wanted to move the bundle to the src folder to keep everything tidy..
is there any way to move bundle from vender to src directory?

Yes, copy past the namespace directories to the src directory...
But really, why do you want this? The directory structure is not important and even if it was, it is better to put the 3th party bundles in the vendor directory to seperate your bundles from 3th party bundles

You must use Sonata easy extend and extend your bundle. This avoid breaks on bundle update.
By default easy extend create the extension in an app folder but you can tell him to put the extension in your src folder with the --dest parameter.
app/console sonata:easy-extends:generate SonataUserBundle --dest="./src"

Related

Symfony .gitignore ignores too much

I have a Symfony 3 project.
In the root dir is the usual vendor dir that composer uses for installation.
In the web dir I also have a vendor dir for bootstrap, fontawesome etc.
In .gitignore I have an entry vendor.
Unfortunately both vendor dirs are ignored. But I want to commit the web/vendor dir.
How is that possible?
May be I have found a solution. I added !web/vendor to the .gitignore.
Is this the right way?
gitignore will recursively ignore everything that matches the "vendor" pattern if that is all you have in your gitnore.
There are some basic rules about gitignore you should familiarize yourself with.
The one here is that gitignore will run relative to the directory it's in.
So, if you add a /vendor entry to the .gitignore in your root dir, then it will only ignore the vendor directory in your root dir. Leave out the slash, and it will drill down as far as it can go and ignore everything that has a vendor in the name, whether it be a file, directory, whatever.
A tip: try looking up sample .gitignore files on github for a specific project type you're using. These are usually good enough to get going.
For symfony, a good one is here: https://github.com/github/gitignore/blob/master/Symfony.gitignore
Yes, that was the right way. Just add !web/vendor.

How to use the css and js file from the vendor folder in Symfony 3?

I'd like to involve jQuery Smart Wizard in my application.
I have update the composer.json and then run composer update.
Here I get the related files in the vendor folder as techlab\smartwizard.
How could I link the css and js file from the twig template?
I have tried to use below command to generate link to the resources.
php bin\console assets:install --symlink --relative
It seems that the command only deal with the folder in resources\Public in each Bundle.
I hope I could use some link as below to get the files.
<link rel="stylesheet" href="{{ asset('bundles/XXX/static//styles/XXX.css') }}">
I know I could create CSS and JS folder under web folder and then copy the related files there. I just wonder if I have to do this manually then why I use composer to install it. I could just download the file and put them in the target folder. That's all.
I am not sure if there is some better way to manage the resource.
Thank you very much for your help.
assets:install command works only if it finds directories/files in Resources/public directory.
I see two options here:
1) create a bundle and add the files in the Resources public directory
2) use bower and install this package as a dependency for frontend.
For this, you may create a `.bowerrc` file to set the
target directory which can be `web/bower`.
Composer is used to manage php dependencies, not frontend ones, except somebody made a package to work with composer and to be integrated in framework.
So, you can use:
1) composer -> php related, backend dependencies
2) bower, npm -> frontend dependencies
I use a precompiler with gulp that manages css, images and js files in the project
Try
php bin\console
To
php bin/console
Where in your command line

Adding composer into Codeigniter

I am using Codeigniter since a year and I also started learning Laravel recently and I noticed that having a composer in your framework really helps you in a many ways.
I notice that the Codeigniter 3 has this option in config.php file to add a composer in it.
$config['composer_autoload'] = TRUE;
so I am thinking to add a composer in my CI.
Is it best practice to add a Composer in CI?
What should be the directory structure for that and is it work smoothly with the CI?
This is how I implemented composer in CodeIgniter 3.It is very easy. You have to install composer on your machine and I think you have it because you use laravel.
First copy and paste composer.json file in the project folder to application folder
Secound in the config.php file $config['composer_autoload'] = TRUE;
Now you have composer in your project. I will saw you an example like how to install mpdf using composer
Open cmd and direct to application folder
Inside application directory Type composer require mpdf/mpdf
Now a vendor folder will be created inside application folder and inside vendor
folder you can see all your packages downloaded by composer.
Now since you autoloaded composer now you can just use the code given by mpdf official manual like
function m_pdf()
{
$mpdf = new mPDF();
// Write some HTML code:
$mpdf->WriteHTML('Hello World');
// Output a PDF file directly to the browser
$mpdf->Output();
}
You can install any packages in https://packagist.org/ like mpdf very simply like this. Remember you don't need to type require_once APPPATH.'/vendor/mpdf/mpdf/mpdf.php'; since you already autoloader composer. If not prefer to autoload composer you must type require_once APPPATH.'/vendor/mpdf/mpdf/mpdf.php' at the beginning of each controllers where you use the mpdf vendor libraries.
in my experience, the best way is installing composer and dependencies independent of CodeIgniter, like 'composer require ', and then give access to the packages in your base controller.
add a file MY_Controller.php to application/core folder and make it extend CI_Controller. then add require_once(APPPATH . 'vendor/autoload.php') at the top. make all your controllers extend this base class, and you have access to all your packages. the same goes if you wanna access them in your models. make the base class MY_Model.php

Zend Framework 2 load class PHPGangsta_GoogleAuthenticator

I'm trying to load a class that has an underscore in it in ZF2.
This is the project I want to use: https://github.com/PHPGangsta/GoogleAuthenticator
The folder paths look like this:
/module
/Application
/Service
/MyService.php
/vendor/
/PHPGangsta
/GoogleAuthenticator.php
GoogleAuthenticator.php has a class named PHPGangsta_GoogleAuthenticator which I want to use in MyService.php, without having to require any files.
Also, I cannot change files inside PHPGangsta, because the project is submoduled under git.
Can you help configure zf2 class autoload?
Assuming you installed ZF2 using Composer (which is the recommended method), edit your composer.json to add phpgangsta/googleauthenticator to the require section. Then run composer install. That's it. You should then be able to use the library in your application - you don't need to do any additional autoload configuration.

Symfony 2.3 - after moving vendors dir autoloading MyBundle got broken

I wanted to make vendor directory common for more than one project. So I moved it and updated my app/autoload.php accordingly: ($loader = require __DIR__.'/../../../vendor/autoload.php')
It worked to some degree - it seems Symfony was able to find it's way to vendors directory BUT somewhere along the way autoloading my bundles got broken. I get this:
FatalErrorException: Error: Class 'My\FooBundle\MyFooBundle' not found
in (...)\Symfony\app\AppKernel.php line 19
How should I solve this? Should I somehow add dir with my bundles to app/autoload.php?
I understand that Composer is responsible for autoloading anything within vendors dir, but not my bundles, so I guess that messing with composer.json doesn't make sense, right?
You should check the vendor/composer/autoload_namespace.php file. The $vendorDir should stay the same, but the $baseDir certainly needs to be changed.
Make sure the line "psr-0" in composer.json point to correct path. In your case, I guess it should be YourBundleFolder/src. Normally it's just src because src is same level with composer.json. Now you have moved the vendor folder, I guess you moved the composer.json also. That's why it can not find your bundle.

Categories