2

On most of PHP frameworks, they have our CLI PHP command to do something (Create controller, create database ... etc).

I have a framework created from scratch, for that, I want to create my own CLI PHP command to easier my work.

I search a lot for this point, but unfortunately no information I get it.

Is there any solution? or method to do it?

4
  • 1
    You just need to write any script and run it. You can autorun them without explicitly wrting php with #!/usr/bin/env php at the begining of the file. Anything more complicated is up to you. Commented Apr 11, 2019 at 8:57
  • github.com/ArtisticPhoenix/Cli - Not really a appropriate question, but lucky for you I made this thing. Commented Apr 11, 2019 at 8:57
  • Here is another project of mine (I just did) that uses this library, you can use it as an example if you want github.com/ArtisticPhoenix/SCSS Commented Apr 11, 2019 at 9:05
  • Laravel Zero or splitbrain come to my mind Commented Apr 11, 2019 at 9:10

1 Answer 1

2

After answers of users,

You can create your own CLI Command by creating a PHP script and call it with this command : php nameofyouscript.php or you can create a file without extension and add #!/usr/bin/env php on the first line and write you php code, to call it you can use this command : php nameofyourscript

To receive information from user you can add this line to you php code :

$line = readline("Write something: ");
echo $line

Finally, if you want to create a command like this php nameofyouscript something you can add this on you php code :

echo $argv[1]; //to get 'something'

PS: If you have any other information please edit this comment or write your own.

I hope that can help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.