PhpStorm configure vendor extensions individually - php

I have the following Magento 2 standard project structure, but this can apply to any php composer based project:
.
..
.git
.gitignore
composer.json
composer.lock
vendor/Acme/module1
vendor/Acme/module1/composer.json
vendor/Acme/module1/.git
# .gitignore contains a directive to ignore the vendor directory because the project structure contains nested repositories
Is there a way to configure PhpStorm to highlight my changes individually for each vendor extension? At this point all my vendor changes are not displayed (because of the directive in the .gitignore file). The only changes that are highlighted are the ones in the main project repo.

You may install your vendor module via symlink using this manual https://johannespichler.com/developing-composer-packages-locally/
Then you can add this external folder to your project to simplify development via File | Settings | Directories | Add Content Root action.
Then you need to add your module VCS to your project via File | Settings | Version Control
Now you can easily manage your changes separately.
For even better control I recommend you use changelists

Related

Is it possible to validate vendor folder integrity in composer?

I just inherited a composer project in a very bad shape. They sent me a zip file with the vendor directory in it and I suspect that the previous developer has edited files directly inside vendor.
Is there a way to "validate" the vendor folder to ensure that the files inside are unmodified?
Change the name of the old vendor to something else.
Execute composer install again.
Run diff to compare both directories.
E.g. for a sample project where I intentionally modified a single file inside vendor.
$ mv vendor vendor_old
$ composer install
### install output...
$ diff -rq vendor vendor_old
Files vendor/autoload.php and vendor_old/autoload.php differ
Files vendor/composer/autoload_files.php and vendor_old/composer/autoload_files.php differ
Files vendor/composer/autoload_real.php and vendor_old/composer/autoload_real.php differ
Files vendor/composer/autoload_static.php and vendor_old/composer/autoload_static.php differ
Files vendor/symfony/console/Terminal.php and vendor_old/symfony/console/Terminal.php differ
You can mostly ignore the changes to the autoload* files, but with this listing you can concentrate in those other files that report differences (and run a more exhaustive diff from them).
In the example, only vendor/symfony/console/Terminal.php was actually modified.
Copy the project into some other folder, and delete the vendor directory. Run composer install and compare two vendor files.
The easiest way to do this is by using composer status command.
The prerequisite is that package is installed from source (as described on the official Composer site):
If you often need to modify the code of your dependencies and they are installed from source, the status command allows you to check if you have local changes in any of them.

New files on installation of project Symfony 3

I've installed a Symfony project on Windows (developed on a Mac) and after composer install I got 3 new files :
bin/symfony_requirements
var/SymfonyRequirements.php
web/config.php
Do I need to version those files or ignore them in the .gitignore file ?
web/config.php
From SensioLabsInsight,
This config.php file should only be used to bootstrap a Symfony application. Before releasing to production, you should remove it, otherwise attackers could get valuable insight about your application.
var/SymfonyRequirements.php
This file is used by Symfony Check CLI Script to check for minimum requirements of configuring & running a Symfony App. It's a Common Post-Deployment Task.
See this question Should the changes of SymfonyRequirements.php be included in version control? and the documentation.
No need to add these files in git.
I use .gitignore as like this and its working fine for me and my team.
/web/assetic/
/web/bundles/*
/var/bootstrap.php.cache
/var/cache/*
/var/sessions/*
/app/config/parameters.yml
/var/logs/*
/vendor/
/bin/
/web/uploads/
/.project
/.buildpath
/.settings

Setup a local configuration file in Codeigniter

Probably my English is not the best,i will try to re-explain.
SERVER ROOT
—> global_application_folder
-> global_system_folder
—> app_1
- index.php
- local_config_file.php
- local_database_file.php
-> app_2
- index.php
- local_config_file.php
- local_database_file.php
-> app_3
- index.php
- local_config_file.php
- local_database_file.php
In any folder app_N i have "index.php" that takes care to say where to find the application and system folders.
"local_config_file", it should serve to change some settings in "config/config.php" like: $config['base_url'], $config['sess_cookie_name'], etc, etc.
"local_database_file", it should serve to change some settings in "config/database.php".
Everything works, now i have to find a good way to override the configurations i need to change for each app.
In the previous link: http://caseymclaughlin.com/articles/setup-a-local-configuration-file-in-codeigniter, (which explains what I need ), it describes a way but it does not work, perhaps because dated.
Doing various tests, the only working way i've found is to add, for example, at the end of the "config/config.php"
include_once(FCPATH . 'local_config_file.php');
including the file (in this case "local_config_file.php"), that is not found in the "global_appliacation_folder/config" folder, but within the various folders app_N, that's why FCPATH in the path of inclusion.
So if i will be app_1, the included file ("local_config_file.php"), will be inside the folder app_1
I would advise to make it all separate repositories and use and dependency manager. eg. composer for php.
With that approach get better control of individual applications, with easy way how to distribute changes in the core.
This way you can also leave old apps - to depend on older version of the core fixed at a specific version
You can have
core repo
test app 1 repo
depends on core repo
test app 2 repo
depends on core repo and some other repo
test app 3 repo
depends on core repo legacy version

PHP Composer project standard directory layout

Is there any standard project structure for Composer projects such as the Maven's Standard Directory Layout in PHP?
The newest answer is "yes", based on scanning every package listed on https://packagist.org and counting which directories are being used by the vast majority of packages, i.e. what most people unconsciously agreed upon without coordination:
https://github.com/php-pds/skeleton
The short summary for directories:
If a package has a root-level directory for ...
... then it MUST be named:
command-line executables bin/
configuration files config/
documentation files docs/
web server files public/
other resource files resources/
PHP source code src/
test code tests/
Using this layout pretty much aligns your project with every other project you'd probably use as dependency. Note that you do not have to have EVERY directory, only the ones that actually host files.
The typical layout is this:
src/
vendor/
.git
composer.json
composer.lock
For compatibility purposes, the Git and Composer files should sit in the root of the project.
The source directory should be the root of the source files beginning with the top level namespace of your classes.
The vendor directory should contain all third party libraries imported via composer.
This is the minimum expected standards, particularly for a live project environment. If the project is a library, then the source directory could be omited.
The best example of this is the Symfony2 Standard Edition:
https://github.com/symfony/symfony-standard
After this the convention for frontend assets and controller is normally:
web/
js/
css/
images/
index.php
The index file in this case is your front controller.
This should include a bootstrapper in another directory, or initialize the environment using the configuration in that directory.
For Symfony2 this is the app directory:
https://github.com/symfony/symfony-standard/tree/master/app
Hope this helps, bare in mind this is based solely on my experience and observations.

Autoloading classes when not in same directory as zend library

I've decided that rather than have a copy of the Zend Framework in each application's directory, I'd like to keep it on one location on the server, with the one copy used by all my websites. However, I'd like my app's custom classes to still be within the application folder. So a folder structure a bit like this:
webroot
|...library
| |......Zend
|
|...app1
| |.....Library
| |.......App1
|
|...app2
|.....Library
|.......App2
How can I get Zend Loader to automatically find the classes in App1 and App2? (preferably by just changing something in application.ini or bootstrap.php)
You can create a single library directory, with symlinks to the actual live shared code:
webroot/library/Zend -> /path/to/Zend/library/Zend
webroot/library/App1 -> /path/to/App1/library/App1
webroot/library/App2 -> /path/to/App2/library/App2
Then, you only need webroot/library in your path.
To handle version updates, you can simply change the symlink to point to a new install:
webroot/library/Zend -> /path/to/Zend-test/library/Zend
The Zend Loader will use your php include_path to find files to load.
Simply add webroot/library to your include_path (which you can either do in php.ini or in your bootstrap) and the autoloader should be able to find the framework.
If you are keen to have a shared version of Zend you may as well just use pear (http://pear.zfcampus.org/) to install it and then as long as you have your include_path set to look in your pear dir ( /usr/share/php on my machine ) then you are good to go.
I would advise only to do this for dev machines though, as others have said it's a good idea to be able to control the versions of zend for each app when in production.

Categories