I've installed PHPCI and have added a project named 'myproject' in PHPCI for testing. It is asked that I should include a 'phpci.yml' file in the root directory of the project. Here is how this 'phpci.tml' file should look like:
Click here to see the file pattern. Which part of this file should I edit to include it in my project as myproject's description as given below?
Project root direcotry: myproject
database name: mydb
database user: root
database pass: secret
host: localhost
Can some one please help me in this regard?
First you need to create phpci.yml file in your project's root directory, in your case it will be myproject/phpci.yml . This file contains configuration and usage of plugins. You might also need those plugins in your project for PHP-CI to test build. Use composer to to include those plugins in your project. To do that add another file in your project's root directory myproject/composer.json.
This happens when PHP-CI cannot find a plugin from its own directory, then it uses project's vendor directory to execute those plugins.
Example File/Config Format:
Suppose you have directory structure like this:
./myproject/
./myproject/protected/
./myproject/assets/
./myproject/protected/runtime/
and you want to run PHP-CI on ./myproject/protected/ while looking to skip ./myproject/assets/ & ./myproject/protected/runtime/ directories then your phpci.yml will look like this:
phpci.yml
build_settings:
ignore:
- "assets"
- "protected/runtime/"
setup:
composer:
action: "install"
test:
php_parallel_lint:
directory: "protected"
ignore:
- "assets"
- "protected/runtime"
php_code_sniffer:
path: "protected"
ignore:
- "assets"
- "protected/runtime"
standard: "code-sniffer-settings.xml"
allowed_errors: 10
allowed_warnings: 10
php_unit:
config:
- "protected/tests/phpunit.xml"
args: "--stderr"
path: "protected/tests/unit"
php_cpd:
allow_failures: true
path: "protected"
ignore:
- "assets"
- "protected/runtime"
php_docblock_checker:
allowed_warnings: -1
path: "protected"
ignore:
- "assets"
- "protected/runtime"
php_loc:
directory: "protected"
pdepend:
directory: "protected"
composer.json
{
"require-dev": {
"squizlabs/php_codesniffer": "2.*",
"sebastian/phpdcd": "*",
"phpmd/phpmd" : "#stable",
"phpunit/phpunit": "4.0.*",
"sebastian/phpcpd": "*",
"jakub-onderka/php-parallel-lint": "0.*",
"phpunit/php-code-coverage": "2.0.0",
"pdepend/pdepend": "2.2.2"
}
}
As to answer your question:
Which part of this file should I edit to include it in my project
Change test: section in phpci.yml and remove extra plugins that you don't want to be executed by PHP-CI, while leave composer section as it is, PHP-CI will run composer automatically on its own when testing a build.
Related
I just installed composer to manage my project's dependencies.
But I end up with a problem: how to protect the files that composer created?
Shouldn't there be an .htaccess file at the root of vendor? (for my case at the root of the libsproduction folder)
Here is my composer.json file :
{
"config": {
"vendor-dir": "libsproduction/"
},
"require": {
"spipu/html2pdf": "^5.2",
"phpmailer/phpmailer": "^6.1",
"tinymce/tinymce": "^5.2",
}
}
Composer files (both the vendor directory and the composer.json and composer.lock files themselves) shouldn't be in a publicly accessible place.
But the way to do this is not to create an .htaccess or something similar under a webserver different from Apache. What you should do is serve a directory different than the one containing these directory and files. Nor changing the vendor name as you are doing.
The way this is generally done, by most (if not all) composer based frameworks, is to create a "public" or "web" directory which is the one you would configure your web server to actually serve, and put your application entry file(s) there.
E.g.
project-root-dir
├── public
│ └── index.php
├── vendor/
├── composer.json
├── composer.lock
The directory your web server should point to would be public in this scenario. So visiting users cannot directly see anything that's not within that directory.
To load composer's autoloader so that all packages classes are available, you simply do something like:
// public/index.php
require dirname( __DIR__ ) . '/vendor/autoload.php';
/* your application/script logic goes here /*
This way you can also put any other file that shouldn't be user accessible (configuration, logs, cache, etc) one level up from the publicly accessible directory, and you have work less to protect your sensitive files.
I got a little struggle with renaming dir to public_html for web host.
According to latest tutorial I'm trying to successfully rename it, but every time when i'm trying to run local server using console command I'm getting an error:
[ERROR] The document root directory ".../.../App/public" does not exist.
I'm sure that I'm doing something wrong with code. But I don't know where. I'm very beginner with Symfony.
Here's my code from composer.json:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
}
"public-dir": "public_html"
},
Did I understood something wrong with it?
Thanks for help.
If the code snippet represents exactly what you have in your composer.json then I have noticed that it is not correctly formatted json file. In the "extra", after the value of "symfony" key, you need to put a separator "," then in the next line you may add more key:value pairs. AS in:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
},
"public-dir": "new_public_html_dirname"
}
A not well formatted json file will prevent it from being executed. I hope it helps.
It is important to run composer update.
composer update
As the index.php file is the first file being run (by the webserver) you should just be able to rename the public directory to public_html and it will work, and not need to change anything in the composer.json (though how that would affect the framework code, without at least running any composer-scripts, I do not know).
I've just created a new Symfony 4.2.3 project, and done nothing more than renaming the directory, and running (most) bin/console commands are not affected.
The in-built server will have issues, but you can tell it which directory to use as the docroot with:
mv public public_html
bin/console server:start --docroot=public_html/
[OK] Server listening on http://127.0.0.1:8000
The changes to composer.json are not required.
I'm trying to change the directory of my dependencies on a Symfony 3.4 application.
I need that because I'm working on macOS with Docker and I'd rather have them not shared with the host since the file synchronization is too slow.
The related documentation, says:
The change in the composer.json will look like this:
{
"config": {
"bin-dir": "bin",
"vendor-dir": "/some/dir/vendor"
},
}
That I did
Then, update the path to the autoload.php file in app/autoload.php:
// app/autoload.php
// ...
$loader = require '/some/dir/vendor/autoload.php';
I don't have any autoload.php file in my app directory.
Am I missing something in the doc ?
The application generates the following fatal error:
Warning: require(/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php): failed to open stream: No such file or directory in /vendor/composer/autoload_real.php on line 66
Fatal error: require(): Failed opening required '/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php' (include_path='.:/usr/local/lib/php') in /vendor/composer/autoload_real.php on line 66
I originally created the application with:
$ composer create-project symfony/framework-standard-edition test "3.*"
Open your composer.json file in editor.
Look for "autoload-dev" section
Remove whole "files" part (if exist)
Save file
Run composer install once again
Enjoy the party.
Sample code:
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
},
"files": [
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
]
},
In Symfony 3.4, the file app/autoload.php is removed so you should:
replace old vendor path by the new vendor path directly in web/app.php, web/app_dev.php, bin/console and var/SymfonyRequirements.php files
Rerun the command $ composer install
I had the same issue and it was resolved doing the next.
Follow these 3 steps
1. First of all, modify composer.json to use the new vendor path:
"config": {
...,
"vendor-dir": "/app-vendor"
},
And remove the next line:
"files": ["vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"]
2. Secondly, if you are using docker-compose add a new volume where you'll put your vendors.
volumes:
...
- /app-vendor
PD: /app-vendor is a mounted volume which is now empty directory.
3. Lastly, write require '/app-vendor/autoload.php'; to:
my_project_name/bin/console
my_project_name/web/app.php
my_project_name/web/app_dev.php
PD1: Simply, this line is pointing to the new vendor path.
PD2: It's not necessary to modify any other file (like var/SymfonyRequirements.php as I could read).
Check your changes
Once the changes are ready, remove vendor/ and also remove the containers to avoid future problems.
Start your new containers and execute composer install. Now, /vendor will be /app-vendor, it won't be in the root folder of the project anymore.
For more details, I'd recommend you to go to my docker-symfony repository and check the commits. You'll see a benchmark progression and another tips like cached volumes and non-shared /cache && /logs folders.
All for Symfony 3.4.
I have problems with auto loading the files, I tried to find some solution but with no luck. Here is my file structure:
my-site
- src
- - app
- - - core
- - - - App.php
- vendor
index.php
composer.json
Here is my my composer.json
"autoload": {
"psr-4": {
"App\\":"src"
}
}
Here is my App.php file:
namespace App\Core;
class App {}
and now, if I try (into index.php)
require_once __DIR__ . '/vendor/autoload.php';
use App\Core\App;
var_dump( class_exists('App') );
Where I'm wrong ?
Thanks.
I found my problem, the problem in my case was into the dump-autoload, I tried like this:
composer dumpautoload -o
and now works, thanks guys!
Assuming your App.php has the following namespace based on your directory structure
<?php
namespace App\Core;
class App {
....
}
then
"autoload": {
"psr-4": {
"App\\":"src"
}
}
Basically it's saying package App starts at root of src folder.
my-site
- src
- - app
- - - core
- - - - App.php
- vendor
composer.json
index.php (the file that is doing the autoload if not at this level you need to adjust the file path for loading)
I found my problem, the problem in my case was into the dump-autoload, I tried like this:
composer dumpautoload -o
and now works, thanks guys!
I am developing a Wordpress plugin, I have composer inside my plugin directory at root level. I have installed all of the packages that I'd like to use and then I have PHP use commands loading in each namespace at the top of my plugin file after auto loading the packages.
PHP error
[28-Jun-2017 10:09:37 UTC] PHP Fatal error: Class 'DrewM\MailChimp\MailChimp' not found in /home/xxx/public_html/wp-content/plugins/plugin-name/plugin-name.php on line 44
Plugin file structure
/plugin-name
'- vendor/
'- .gitignore
'- composer.json
'- plugin-name.php
composer.json contents
{
"require": {
"guzzlehttp/guzzle": "^6.3",
"theiconic/php-ga-measurement-protocol": "^2.0",
"mailgun/mailgun-php": "~2.3.4",
"stripe/stripe-php": "^4.13.0",
"mailchimp/mailchimp": "^2.0",
"drewm/mailchimp-api": "^2.4"
}
}
plugin-name.php contents
<?php
/*
Plugin Name: Plugin name
[...]
*/
require 'vendor/autoload.php';
use TheIconic\Tracking\GoogleAnalytics\Analytics;
use Mailgun\Mailgun;
use Stripe\Stripe;
use \DrewM\MailChimp\MailChimp;
Solved: In plugin-name.php, I needed to change
require 'vendor/autoload.php';
to
require plugin_dir_path(__FILE__).'vendor/autoload.php';
Because the current working directory is always the root of the Wordpress installation, not inside my plugin directory.
The reason I wasn't getting an error on the require line is because I had another similar vendor directory in the root of the installation.