Quantcast
Channel: Craft It Online!
Viewing all articles
Browse latest Browse all 92

Symfony: Forget About Permission Settings

$
0
0

Ever wanted to forget about going into symfony.com looking for the configuration chapter of the book and copy pasting the long commands to set acl’s right on your systems? That is not only on your local but also on your server?

Well there was a discussion in a DX ticket that today I stumbled upon and here it is https://github.com/symfony/symfony/issues/11563 and skimming over it I found this pearl from @umpirski. It is called umpirsky/composer-permissions-handler and here it is how you set it up:

         "symfony/monolog-bundle": "~2.4",
         "sensio/distribution-bundle": "3.0.*@dev",
         "sensio/framework-extra-bundle": "~3.0",
-        "incenteev/composer-parameter-handler": "~2.0"
+        "incenteev/composer-parameter-handler": "~2.0",
+        "umpirsky/composer-permissions-handler": "dev-master"
     },
     "require-dev": {
         "sensio/generator-bundle": "~2.3"
 @@ -32,7 +33,8 @@
             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
             "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
-            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles"
+            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::removeSymfonyStandardFiles",
+            "Umpirsky\\PermissionsHandler\\ScriptHandler::setPermissions"
         ],
         "post-update-cmd": [
             "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
 @@ -49,6 +51,7 @@
     "extra": {
         "symfony-app-dir": "app",
         "symfony-web-dir": "web",
+        "writable-dirs": ["app/cache", "app/logs"],
         "incenteev-parameters": {
             "file": "app/config/parameters.yml"
         },

In mac it works like a charm and I am sure it works the same way in servers due to its nice phpspec’ed logic:

<?php
 
namespace Umpirsky\PermissionsHandler;
 
use Umpirsky\PermissionsHandler\Exception\PathNotFoundException;
 
class SetfaclPermissionsSetter extends PermissionsSetter
{
    public function setPermissions($path)
    {
        if (!is_dir($path)) {
            throw new PathNotFoundException($path);
        }
 
        $this->runCommand('setfacl -R -m u:"%httpduser%":rwX -m u:`whoami`:rwX %path%', $path);
        $this->runCommand('setfacl -dR -m u:"%httpduser%":rwX -m u:`whoami`:rwX %path%', $path);
    }
}

It is a very good example to learn and review phpspec niceties too!

Enjoy, thanks @umpirski for a nice package!


Viewing all articles
Browse latest Browse all 92

Trending Articles