Slim PHP Framework PhpStorm IDE autocompletion Solution

I am a big fan of PHP Slim Framework. But sometimes, I realized that when I work with large and complex libraries with Slim as dependency. It just kills my productivity, it kills my valuable time too. It’s all because of I can’t remember all the method names, properties of my dependent class or libraries. And with Pimple dependencies Slim Framework don’t have any way to bypass referencing of my third party libraries which I add through it’s container as dependency. So I decided to figure out a solution for me.

First, I just installed and configured slim framework and here is my scripts.

<?php
//index.php
require "../vendor/autoload.php";
$app = new \Slim\App();
$container = $app->getContainer();

/**
 * @return \ShahariaAzam\Classes\HintsClass
 */
$container['hints'] = function () {
 return new \ShahariaAzam\Classes\HintsClass();
};

$app->get('/foo', function (\Slim\Http\Request $request, \Slim\Http\Response $response) {
 /** @var Dummy $this */
 $this->hints->printHelloWorld();
 $response->write("Hello World");
});

$app->get('/another-foo', function (\Slim\Http\Request $request, \Slim\Http\Response $response) {
 /** @var Dummy $this */
 $this->hints->printHelloWorld();
});
$app->run();

 

And I created a class HintsClass. Now the main trick is, I created a dummy _ide_autocomplete.php file in the project root and defined all the containers key as public property. Like this.

<?php
//src/HintsClass
namespace ShahariaAzam\Classes;

/**
 * Class HintsClass
 * @package ShahariaAzam\Classes
 */
class HintsClass
{
    /**
     * @var int
     */
    public $test = 1;

    /**
     * @return bool
     */
    public function testMethod()
    {
        return true;
    }

    /**
     * @return string
     */
    public function printHelloWorld()
    {
        return "HelloWorld";
    }
}

 

Now our goal is from inside route, our PHPStorm IDE will show the autocomplete and hinting for code completion when we will access this class with $this->hints->[ctrl+space to see autocompletion]. And in our _ide_autocomplete.php file we wrote the following codes. FYI, this _ide_autocomplete.php will never execute. It just used for giving IDE as a referential hinting for all the properties .

<?php

//_ide_autocomplete.php
class Dummy
{
    /**
     * @var \ShahariaAzam\Classes\HintsClass
     */
    public $hints;
}

 

You will see in this Dummy class file according to our slim containers[‘hints’], I just mentioned the same return reference here. And see my main index.php, in every route I just gave IDE hints about the $this context with

/** @var Dummy $this */

And after that from route context IDE will show the autocompletion of our dependencies like $this->hints[ctrl+space to see suggestions].

You can see my whole scripts are in GitHub https://github.com/shahariaazam/slim-phpstorm-autocomplete. And see this work in YouTube, https://www.youtube.com/watch?v=jyEvApLRofw .Please let me know if any issue found, write me in comments. Thank you.

Install Bengali font in Linux/Ubuntu – Write Bengali in Linux

Ubuntu hasn’t any default solution for Bengali font or Bangla input methods. To use Bangla in your Linux PC you have to install it manually first. It’s pretty simple. Just follow my following steps.

sudo apt-get install ibus ibus-m17n m17n-db

The above command will install iBus (input methods), ibus-m17n and m17n-db in your system.

Now you have to write the following command to setup iBus.

sudo ibus-setup

now you will see a ibus setup window to configure. (see following image)

Setup iBus in Ubuntu

Select Unijoy (m17n) as Input methods from the drop down list. Select it and click on Add from the right side. In this same way also add ispell (m17n) for English support also. select it and add it. Now after adding both Unijoy and ispell just close the setup dialogue. And you are done!!

If you are using Ubuntu 14.04 (LTS) version then please read my another updated post about to write bangla in Ubuntu 14.04