Skip to content

Instantly share code, notes, and snippets.

@juangiordana
Last active December 5, 2019 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juangiordana/cd7da1332ce473f0909c7cae72df71a9 to your computer and use it in GitHub Desktop.
Save juangiordana/cd7da1332ce473f0909c7cae72df71a9 to your computer and use it in GitHub Desktop.
Sublime Text 3 / PHP workflow

PHP

mkdir ~/bin
sudo apt install php-cli php-xml

Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=bin --filename=composer
php -r "unlink('composer-setup.php');"

Add Composer to PATH environment variable by modifying either ~/.profile or ~/.bash_profile.

cp ~/.profile{,.bkp}
cat >> ~/.profile << "EOF"
if [ -d "$HOME/.config/composer/vendor/bin" ] ; then
    PATH="$HOME/.config/composer/vendor/bin:$PATH"
fi
EOF
source ~/.profile

composer global require "squizlabs/php_codesniffer=*"

composer global require friendsofphp/php-cs-fixer

Configure php-cs-fixer for PSR-2 coding style.

cat > ~/.php_cs << "EOF"
<?php

return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2' => true,
        'array_syntax' => [ 'syntax' => 'short' ],
        'no_unused_imports' => true,
    ]);

EOF

Sublime Text

{
    "caret_style": "phase",
    "ensure_newline_at_eof_on_save": true,
    "ignored_packages":
    [
        "Vintage"
    ],
    "line_padding_bottom": 6,
    "line_padding_top": 6,
    "rulers": [80, 120],
    "show_tab_close_buttons": false,
    "translate_tabs_to_spaces": true,
    "trim_trailing_white_space_on_save": true
}

Install Package control and then the following packages in order with it:

Make sure the config path points to the previously created .php_cs file.

{
    "config": "/home/juan/.php_cs",
    "on_save": true,
    "on_load": false,
    "exclude": [
        ".*[\\\\/]vendor[\\\\/].*", // vendor-path (used by Composer)
        ".*\\.phtml$" // files ending with ".phtml"
    ]
}

After installing the Xdebug Client add the following into your project settings:

Notice that the path_mapping format is path_mapping: {"guest OS path": "host OS path"}.

{
    "settings":
    {
        "xdebug":
        {
            "path_mapping":
            {
                "/home/vagrant/Projects/project.name/repository": "/home/juan/Projects/project.name/repository"
            },
            "url": "http://project.name/"
        }
    }
}

Then log in into your Homestead environment, set your preferred default PHP version, turn on the Xdebug extension and restart the FastCGI service for the changes to take effect.

homestead ssh
php73
xon
sudo service php7.3-fpm restart

Restart Sublime if necessary.


Links of interest:

Professional PHP Workflow in Sublime Text 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment