How to automatically include autoloader to PHP script? - php

I wan't to run php classes scripts from my IDE with PHP CLI.
When I launch files in which there are other classess specified, PHP shows error - because it can't find this classes. What should I add to command-line to automatically include my autoloader into the launching script?

I nedded to just add an Interpreter option:
-d auto_prepend_file="path to autoloader"

Related

Laravel preset React: problems encountered when `npm run dev` is executed

I have some issues with using React in Laravel 5.5. Every time I add or make changes to a component, I have to run npm run dev to compile the thing. When I do this the contents of css/app.css get reset, so I cannot write styles to this file.
Styles get unchanged if I have them in another CSS file, but I'd like to have my main styles written in css/app.css.
How can I do this?
Keep all your css styles in a file in your resources directory and add the below code to end of your webpack.mix.js file.
mix.styles('path to your css file in resources directory', 'public/css/app.css');
If you are using sass use the below code
mix.sass('path to your css file in resources directory', 'public/css/app.css');
Also you no need to run npm run dev each time you make changes to your components. just run npm run watch and it will continuously look for changes and re-compile the components if anything is changed.

Run yii commands from shell script

I am trying to make a script which automaticly loads a project from a git repository. I run exec() from a php file with name of the shell script as an argument. The script looks something like this:
git pull
php yii migrate
The git command works well, but the yii command is totally ignored. I'm doing this from the root of the directory of the yii site, so it should work, but it doesn't.
How can I fix this?
if you are using Yii version 1.x, you have to run your command from inside protected directory
cd protected
php yiic.php migrate
First of all, if you want to run console application in Yii2, just use
yii <route> [--option1=value1 --option2=value2 ... argument1 argument2 ...]
Second: yii migrate is the defined console command to upgrade a database to its latest structure. So it probably does its work, but not that you want to.
Try to rename your console command.
Reference links to read:
Guide: console commands
Guide: migrations (part with yii migrate).

Including PHPUnit.phar in script

I installed the latest release of PHPUnit using the phar according to the documentation. I have some scripts to compile a code coverage report using the PHP_CodeCoverage object. With the update, when I try to include phpunit.phar phpunit is actually run. The script outputs the list of options for running PHPUnit and then exits.
How can I include the file so that I have the PHPUnit objects available in my script?
The line that I tried was
require '/usr/local/bin/phpunit.phar';
PHPUnit creates and registers an autoload function for including its files in phpunit.phar. I was able to use the PHPUnit classes in my script by extracting this function.
The code is available on Github
Basically, all the class paths are mapped and then included via require phar:///user/local/bin/phpunit.phar/<class path>

How to change the Symfony2 Behat Bundle default Feature context file (FeatureContext.php by default)

I use Symfony2 BehatBundle, version=v1.0.0 and I want to change the name of the main feature context file. Now when I run the behat using command:
app/console --env=test behat #NameOfMyBundle
file src/NameOfMyBundle/Features/Context/FeatureContext.php is used
I want to use custom main feature file, for example src/NameOfMyBundle/Features/Context/MyCustomContext.php but I don't know how. According to the behat documentation:
By convention, the context class should be called FeatureContext, but this could be easily changed through the cli configuration.
However, this configuration option is nowhere to be found. I tried something like:
app/console --env=test behat #NameOfMyBundle --context "MyCustomContext"
but it fails.
Does anyone know how to change this main feature context file (preferably, using cli)?
Thanks!
The context class can be changed in the configuration file: http://docs.behat.org/guides/7.config.html#context
Environment variables can be used as well: http://docs.behat.org/guides/7.config.html#environment-variable
The bundle is no longer maintained. Use the extension instead: http://docs.behat.org/en/latest/cookbooks/1.symfony2_integration.html#installing-and-enabling-symfony2-extension

Does symlinking a file change how the file is parsed in php?

I have a php application that relies on several classes to function properly. If I take one of the application's class files
/my/folder/class.php
then move it somewhere else
mv /my/folder/class.php /my/other/folder/class.php
then in its place inside of
/my/folder/
I create a symlink to it called class.php via
ln -s /my/other/folder/class.php /my/folder/class.php
I would expect my application to be unaffected, but instead this is breaking it. I know the symlink is valid since at the command line I can do
nano /my/folder/class.php
and everything looks as I would expect it to. Am I missing something fundamental about the behavior of symlinks, and/or how apache or php processes them? Is it changing the working directory or $_SERVER['DOCUMENT_ROOT']? I can not figure out why this would have any affect on my application.
I am using Apache server in CentOs.
Thanks!
The only difference would be if you are using require_once or include_once and you are mixing the symlink path with the real file path. In this instance, the X_once is going to think those files are different and load it twice (which will of course cause problems if you define any classes or functions).
Would probably need an actual error message to guess any further.

Categories