I have an application with a Symfony Console based CLI. The application does not use the Symfony framework, just the Symfony Console component.
When I execute
php app/myapp
I get the usual overview with the name, version, options and registered commands shown. Suppose I just have one command, called "displaykittens". What I want to be able to do is
php app/myapp d <TAB>
And have it complete to
php app/myapp displaykittens
As is kinda expected in a modern unix environment. Unfortunately there appears to be no tab completion whatsoever. The Console Component itself provides an utility that allows doing something along these lines in commands themselves. That does not help me with getting tab completion for the commands though. Is this possible somehow?
You might like this extension https://github.com/stecman/symfony-console-completion
It allows you to set up both active commands and our own suggestions
Symfony 5.4+ has autocompletion natively.
You can get more information about autocompletion with bin/console completion --help.
For example with bash you can add this in your ~/.bashrc.
eval "$(/var/www/app/bin/console completion bash)"
Official announcement: https://symfony.com/blog/new-in-symfony-5-4-console-autocompletion
I don't know if it is possible with the normal bash shell. But if you use zsh you can install oh-my-zsh. There is a great plugin that does exactly what you ask for: Oh-My-ZSH Symfony2 plugin
The Application class of the Console component can be wrapped in a Shell class, provided by the same component. That provides some amount of auto completion.
According to people on the #symfony IRC on freenode, there is no way to have the console app provide autocompletion out of the box, since changes to the shell config need to be made.
Related
I've acted in accordance with this guid Link.
Then, I created Repos.php file in /app/extensions/command/ And run li3 in command line but do not see the following message:
COMMANDS via app
repos
I see the following text only:
Lithium console started in the development environment. Use the --env=environment key to alter this.
COMMANDS via lithium
create
The `create` command allows you to rapidly develop your models, views, controllers, and tests
by generating the minimum code necessary to test and run your application.
g11n
The `G11n` set of commands deals with the extraction and merging of message templates.
help
Get information about a particular class including methods, properties,
and descriptions.
route
The route command lets you inspect your routes and issue requests against the router.
test
Runs a given set of tests and outputs the results.
See `li3 help COMMAND` for more information on a specific command.
Have I done something wrong?
This is just a general question, how does Laravel Artisan able to create proper .php file e.g. make:controller with the correct formatting and line breaks?
Is there a good PHP script which can help one develop similar php codes.
Thanks
Ultimately, Artisan relies on Shell scripts included with Laravel. Which are written in the language of Shell and reside in files ending with the extension .sh. Here is a website that contains more explanation of what those are and how to develop them: https://www.shellscript.sh/ If this is ever unavailable simply searching "How to create a shell script" will get you the answer.
PHP can execute these scripts, for example, when you visit that PHP page in your browser, or you trigger it from the command line, assuming you have PHP installed on your server.
Artisan, is custom built to allow you to extend it with more commands, and there are tutorials available to show you how to do that, but it's a completely separate process from creating custom shell commands.
PHP files are just text files, you can easily create them with any language. Also in Laravel usually used so called stubs, templates for classes like migrations, controllers etc.
Just go and look how as Laravel does that under the hood.
I've already spent two days trying to make a good work environment with VIM for a framework, in this case, laravel.
All is perfect as always, but there is a very important issue:
I can't get omnicomplete properly working
I've tried all that I found via google:
-phpcomplete: despite in other of my projects works well, it seems that gets mad with composer. Doesn't recognize facades nor common methods for the framework.
-ctags: helps with some methods, but still a mess with omnicompletion.
-phpcomplete-extended and phpcomplete-extended for laravel: author doesn't maintain this plugin anymore (logical since frameworks change so quick) so does not work anymore.
-PIV, uses standart phpcomplete, so same issue.
-padawan.php I couldn't get it to work, IMHO poorly documented
Is there any vim user who could manage to get omnicompletion functionality properly?
I'm starting to think I should move from vim since it's not ready for these new technologies :'(
Grep AppServiceProvider against tags file:
AppServiceProvider app/Providers/AppServiceProvider.php /^class
AppServiceProvider extends
ServiceProvider$/;" c namespace:Furbook\Providers
Furbook\Providers app/Providers/AppServiceProvider.php /^namespace
Furbook\Providers;$/;" n boot app/Providers/AppServiceProvider.php /^
public function
boot()$/;" f class:Furbook\Providers::AppServiceProvider
register app/Providers/AppServiceProvider.php /^ public function
register()$/;" f class:Furbook\Providers::AppServiceProvider
This has been one of my top concerns, here are my preferred options:
Phpactor. My current choice, works pretty well and it's main dev is really active. Fast and has A LOT of refactoring tools. Great for composer projects.
ctags
I use phpcomplete and ctags (patched for php), but still no autocompletion for facades, I resolved this with the Laravel 5 IDE Helper Generator. The idea is to generate a _ide_helper.php file with classes and methods for facades first, and then create the tags.
I also created a function in my vimrc, so I can automatically generate the tags.
function! GenTags()
if isdirectory("./vendor")
echo '(re)Generating framework tags'
execute "!php artisan ide-helper:generate"
echo '(re)Generating tags'
execute "!ctags -R --filter-terminator=php"
else
echo 'Not in a framework project'
if filereadable("tags")
echo "Regenerating tags..."
execute "!ctags -R --filter-terminator=php"
else
let choice = confirm("Create tags?", "&Yes\n&No", 2)
if choice == 1
echo "Generating tags..."
execute "!ctags -R --filter-terminator=php"
endif
endif
endif
:endfunction
command! -nargs=* GenTags call GenTags()
GenTags()
eclim
-- install eclipse, don't use eclipse installer, better untar directly
-- install eclim, use the eclim installer.
-- For complete code completion change your models to extend Eloquentinstead of Model
-- and the plugin YouCompleteMe (you can try any other)
PHP Language Server
It's better and more automated than ctags.
Despite autocompletion is still a bit worse than eclipse (eclim), the Php Language server is developed on PHP, which means a lot of PHP users can contribute to the project and it's pretty active and improving.
Plug 'roxma/nvim-completion-manager'
" (optional) javascript
Plug 'roxma/nvim-cm-tern', {'do': 'npm install'} "
"(optional) language server protocol framework
Plug 'autozimu/LanguageClient-neovim', { 'do': ':UpdateRemotePlugins' } "
"(optional) php completion via LanguageClient-neovim
Plug 'roxma/LanguageServer-php-neovim', {'do': 'composer install &&
composer run-script parse-stubs'}
If anyone wants to know more can check my vimrc at github
Talking about padawan.php that's true about documentation, I haven't spent enough time to make it more or less useful, but installation of padawan shouldn't be that hard:
Install padawan.php via composer global require mkusher/padawan
Configure your $PATH
Install padawan.vim
Generate index for your project
I'm not sure whether Laravel projects will work out of the box or you still will need ide helper, but general php things should work well.
Disclaimer: I am not a PHP programmer and I know nothing about PHP.
First of all, if an auto-completion mechanism is essential for your work, then you should probably choose a proper IDE for the programming language you're working with. Vim includes a framework for auto-completion, which does not mean that it is implemented for all supported languages. And even if there is an omni-completion function available you mileage may vary, depending on how well developed it is.
From what I can gather in other questions (in particular Vim PHP omni completion), the best PGP completion plugin is phpcomplete, so I've installed it.
I then downloaded laraval from here and ran ctags 5.9~svn20110310 (available in Debian Jessie) using the following command:
ctags -R --filter-terminator=php
Using the following test file:
<?php
$example = new AppServiceProvider();
$example->
?>
when I press i_ctrl-x_ctrl-o I get the following suggestions:
boot( f )
register( f )
As it can be seen, there is no long list of methods.
I've also tried to use Universal Ctags that includes the patches required by phpcomplete plugin, but in order to make it work I had to use the following syntax:
ctags -R --fields=+aimS-s --filter-terminator=php .
That is, the extra -s was required.
Maybe you can work from here and test this in more detail in your environment.
I am new to testing. All i knew was we PHPunit for testing various functions within class and then i know selenium for browser testing.
I know we can write php to link with selenium web driver to do headless testing of browser.
I am not able to get how does behat and mink come in there. Are these seperate from selenium and they are the alternatives of selenium.
Can i do aweb application tetsing without beaht, mink and only with selenium and php
PHPUnit and Behat are similar, both being testing frameworks. They allow you to test your code, by using different approaches:
PHPUnit tests are based on code you write to check how your classes behave under the required circunstances. A lot of people use this type of framework to practice TDD, but you can of course write tests after the code, or for code written a long time ago.
Behat tests are written in a human readable way, and they are supposed to allow everyone involved in the project to read them. This type of testing is called BDD. You can write tests that explain in (nearly) plain english how your system is supposed to behave.
IMO PHPUnit is more general and is the preferred way of writing most tests. I use Behat for testing my systems general behavior, and PHPUnit for unit testing every class and method independently of others.
On the other side, Mink is a library that allows you to browse programatically, using PHP, and access the contents. It can be used to control in a unified way a lot of browsing systems like Selenium, Zombie, etc. each of them based on different technologies.
You can use Mink outside Behat, but they are usually used together because this way you can write tests that show how a website behaves: Given I enter my credentials in the login form, And press the submit button, I should see my profile page...
And yes, you can use PHPUnit and Selenium together as explained in the docs...
I would like to be able to integrate a the documentation generator from within my web interface.
I had a look at the docbuilderproject which is a web-based generator provided with phpDoc itself, but I could not identify for sure what was the command that was actually triggering the beginning of the process.
Do you know where I could get some help finding how to execute the phpDoc script programmatically?
PS: I am running PHP on IIS.
Docs should be generated by the integration system, i.e. Jenkins or phpUnderControl. They provide tasks for it.