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.
Related
Does anyone know of a basic unit testing framework for PHP that does not require Composer in order to use it? The project's testing requirements are simple, and I expect any framework would be fine. I'd be very happy with PHPUnit if there's a way of using that without Composer, though I don't think that's possible. The alternative is to roll my own, but I'd rather not do that unless it's necessary.
I know Composer is a perfectly good system, and if the decision were mine, we'd be using it. But it's not my decision, and it has been made clear that the project leader would rather not have any unit testing if the alternative is to use Composer. That's wholly irrational, I know, but it's not a battle I have time to fight.
Actually, if you look at the installation docs, composer is not even stated as the preferred way to install PHPUnit.
The Phar version of PHPUnit can be used instead. It's easy to install and does not require composer.
To execute the tests, instead of a composer script, simply create a bash script (or cmd/powershell if you are on Windows). Although, depending on the configuration you use, it might also be as efficient to directly execute the phar.
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.
I'm new to the Zend Framework but have used PHP in the past. I've gone through the basic tutorial provided by Zend, and understand a lot of it, but I'm fuzzy on the installation process. There seems to be many different ways to install, is that right? Here are the ways I've seen:
Download .zip file and manually extract
Use command line with composer.phar
Use command line with zftool
If someone could give a brief explanation of each of those above methods, how they differ, and which one is better, that would be great!
Also, two more quick questions on topic:
The tutorial mentions including Zend in your PHP include path. Why would you need to do this if the framework is included in the projects directory?
Is there a way to install the framework without the skeleton app?
Thanks in advance!
I'll only go about the 2nd set of questions:
You don't. You either have it inside your include path or inside your projects.
php composer.phare require zendframework/zendframework 2.2.*
Your first question is rather opinionated and it heavily depends on your workflow. To quote some song lyrics:
Sei ying there is no special move that is best, it all depends, any move could be best,
its up to you when the times right, to move correctly, accurately and with great speed...
tl/dr choose the method that seems most practical to your solution.
Try this website: http://www.packtpub.com/article/building-your-first-zend-framework-application
It shows how to install, add a virtual host and skeleton application and add modules to that application.
Happy learning
Use Zip if you dont have access to other methods (composer or git). With Zip you wont be able (easily) to upgrade or downgrade components.
composer is great because you can configure your needs. for example:
"require": {
"zendframework/zend-config": "2.2.*",
"zendframework/zend-http": "2.2.*"
},
More info: http://framework.zend.com/downloads/composer
Use Git if you wish to be on the edge (more hard to maintain versions)
Situation
I have a PHP project with lots of classes with lots of relationships in lots of folders following the Zend Naming Convention.
I use the NetBeans IDE 7.1.
I work under Windows 7.
Goal
I need to see a graphical representation of the class relationships, possibly in varying depths and varying degrees of complexity. Also, it would be nice if the classes in the diagram are clickable. I do not necessarily need to generate documentation.
Attempts
1. Within NetBeans
NetBeans is an awesome IDE with lots of features. In fact, it recognizes class dependencies, and it would be wise to assume that it has some sort of way to graphically view this relationship, natively, or through a plugin. Such a plugin exists, but is for version 5.5. I have 7.1, and it's not compatible. Fail.
2. Enterprise Architect
A simple google search brings up Enterprise Architect as an all-capable, completely comprehensive tool for solving such problems. So, I download and install. I'm not going to go to the detail of how I couldn't understand how to do anything, and how the tutorials are bragging about what the software can do, but rarely say how.
So, I imported the source. It generated many different classes and parsed all the members. Also, it generated the class diagrams. "Perfect!", I though, but alas. The class diagrams only show relationships between classes, the files of which were in the same source folder, despite the relationships being visibly registered in the classes' properties. A search for documentation on how I could merge all these diagrams into one was unsuccessful. Fail.
NOTE: I created a parallel thread before this one here.
3. PHP_UML
Found this PEAR tool. Looked good. So, I read through documentation on how to install it for my setup from various sources, and ran it. First, I used the html output format. Great! Lots of documentation with an index, bla bla bla. However, the best it could do in the direction I want was this:
Needless to say, I guess, that this is a very poor, super simplified version of what I actually need. Conclusion: fail.
4. Enterprise Architect + PHP_UML
However, PHP_UML can also generate XMI. Wow. Very nice. I can store my relationships and view them in different ways and exchange with other people.
So, I imported it into Enterprise Architect. Result: same as before with Enterprise Architect alone, only no class diagrams. Just the classes. As far as I've read about it, I can now manually create the relationships. Epic fail.
5. ArgoUML + PHP_UML
Somewhere through my search for solution I stumbled upon someone's comment that said they use ArgoUML. Downloaded and installed. XMI imported with some hassle (had to change version explicitly to 1). Fail (see Attempt 3).
Conclusion
Such a seemingly trivial task, and yet, so difficult. Do I have to go through this whole list, trying out each application?
One of the ways to do this would be to take the approach illustrated in my attempt 2 or 4,
and then follow instructions given here for Enterprise Architect.
To generate an XMI file using PHP_UML:
Follow these instructions to install PEAR if not installed already, if you have PHP installed separately.
If you are using XAMPP under Windows (my case), follow these instructions to add PEAR to the PATH env variable and thus make PEAR available through CMD, and to learn how to install packages in both *nix and Windows systems. Hint: the PATH separator is ";" (semicolon) for Windows.
In some setups, like if using XAMPP, you may need to activate the XSL extension. In this case, open your php.ini file (you may need Administrator privileges to save it), and uncomment or add the following line to the bottom of the "Dynamic Extensions" section: extension=php_xsl.dll.
Install the PHP_UML package with pear install PHP_UML.
Execute phpuml -f xmi -o name_of_output_dir. If you're planning to use the generated XMI with some older programs later, you may need to specify XMI version 1 by adding -x 1.
For me, this did not work immediately, saying that I am missing ../../data/xmlschema.rng. Not sure why this happened, but if you get a similar error, you can download it from here and place it into the data folder right under your PEAR directory.
This XMI can later be used with Enterprise Architect, ArgoUML and other XMI tools.
(Edit : This answer is an alternative for people that want to generate UML class diagram from a PHP project, it doesn't explains how to read XMI files)
Goal
I need to see a graphical representation of the class relationships,
possibly in varying depths and varying degrees of complexity. Also, it
would be nice if the classes in the diagram are clickable. I do not
necessarily need to generate documentation.
If your goal was to generate a class diagram from a PHP project, I found a better solution than use PHP_UML. What you probably want is BoUML, with this software, you can select a PHP project folder and reverse engineering it. Then create a class diagram. When you drag&drop the class on it, the relations are there unlike AlgoUML (If I'm not wrong). XMI files are no longer useful in this case.
I would like to package PHPUnit and various other test dependencies into a phar and put that into svn. This way I can run phpunit on any client machine without needing pear. Can this be done?
Current status:
Work on a phpunit.phar has started in the phpunit repo but the generated phar is not stable and not feature complete.
If it gets there there will be official releases
Original answer:
If you can I'll give you 500 rep, a 100 Bucks and my first born.. well no.. just the first two.
To be serious:
I've nagged the creator of PHPUnit about this topic on at least 3 conferences now and well.. it doesn't seem like it's possible.
There are a couple of issues with that. First off PHPUnit spawns new php processes for test isolation. The problem with this is that a phar can't tell which php executable called it. So if you start phpunit with a custom compiled version it would use the "default" php installed to spawn the isolated tests.
Secondly as far as i know and have been told it's not possible to put static files like images and css in a phar. Which makes generating code coverage a lot harder. That would require some work on that part.
There are other issues i can't recall exactly recall right having to do with xDebug being able to provide code coverage for phars (and phpunit relying on not generating overage for it's own code and so) and others things.
There once was a phar but from my understanding that just doesn't work out with the current state of phpunit and never really worked completly.
I'm not saying it can't be done just that various people already have given up on creating a phpunit.phar including the guy how develops it. (That is just my impression, i of course can't speak for Sebastian here and might be completely wrong, take this as a little disclaimer)
Putting PHPUnit into SVN
You don't have to build a .phar to do so!
For my company I maintain a svnd version of PHPUnit. It's not the recommended way of using it but it works without much issues!
Follow the "using from a git checkout" instructions on the phpunit github site. You then need to put those files into your php include path and it works.
My suggestion would be to create a custom phpunit.sh that modifies the include path and then calls the original phpunit.sh passing along all arguments. It's a little bit of work but it works quite well and it is a hell of a lot easier than creating a phar archive :)
From the new PHPUnit page:
We distribute a PHP Archive (PHAR) that contains everything you need in order to use PHPUnit. Simply download it from here, make it executable, and put it into your $PATH, for instance......