Suggestion for plugin authors: use composer-installer

82 views
Skip to first unread message

ethanpil

unread,
Dec 16, 2016, 1:57:37 PM12/16/16
to Fat-Free Framework
Please take a look here: http://composer.github.io/installers/

Currently we can install F3 via composer, but plugins are still manual install and update. :(

If we can add a fat-free install type, or at least customize the composer.json files of plugins to support the installer, it will be a lot easier to setup a new project ....

Thoughts?

ved

unread,
Dec 16, 2016, 5:49:23 PM12/16/16
to Fat-Free Framework
To be honest, I didn't quite get what's the difference between regular composer support as we have now and this composer installer thingy.

As far as I know, most known and used F3 plugins already have composer support as well as F3 itself. Are you referring to any particular extension?


ikkez

unread,
Dec 16, 2016, 6:28:33 PM12/16/16
to Fat-Free Framework
Since F3 does not dictate any directory structure, IMO those composer installers only make sense for user frameworks/applications build on top of F3, where you know where to put themes, plugins, modules, etc.
most known "plugins" for f3 are just additional library files, which actually can be put anywhere, as long as they are loaded with the composer autoloader.

ethanpil

unread,
Dec 17, 2016, 7:34:30 PM12/17/16
to Fat-Free Framework
I was under the impression that the plugins needed to be in the same folder as the Base class or in the case of Cortex, etc in the proper location relative to DB?

ikkez

unread,
Dec 18, 2016, 5:51:30 AM12/18/16
to Fat-Free Framework
no it's not necessary in case you use the composer autoloader, or you extend the AUTOLOAD paths accordingly.

In case of cortex, you could just download it anywhere and add its lib path to the autoloader like:

AUTOLOAD = "lib/,app/,includes/f3-cortex/"
or in the index with
$f3->concat('AUTOLOAD',',inc/f3-cortex/');

and you are ready to go.
The trick here does the directory structure within the cortex git repository. At its base dir I got /lib/db/cortex.php, so when you add the root dir of that cortex lib to the AUTOLOAD path, for the F3 autoloader it looks like they were in the same directory.

If the composer autoloader is used, this structure isn't even necessary as the composer autoload file contains a map of namespaced classes and their real filepath.
So if you start a new project with composer, do:

$ mkdir test-app
$ cd test
-app/
$ composer init
$ composer
require bcosca/fatfree-core
$ composer
require ikkez/f3-cortex
$ wget https
://raw.githubusercontent.com/bcosca/fatfree/master/.htaccess
$ nano index
.php

and add this setup to your index.php like this:

<?php
// composer autoloader for required packages and dependencies
require_once
('vendor/autoload.php');
/** @var \Base $f3 */
$f3
= \Base::instance();
// F3 autoloader for application business code
$f3
->set('AUTOLOAD', 'app/');
// ...
$f3
->run();

that's about it.
Message has been deleted

ethanpil

unread,
Dec 18, 2016, 1:23:42 PM12/18/16
to Fat-Free Framework
@ikkez your multiple step instructions are exactly the reason I suggested composer-installer in the first place. Why make everyone go through all that when we can just do what everyone else does and just

composer install ikkez/f3-cortex

I don't need instructions. I can do it manually any time. This suggestion will make things easier for everyone and make F3 easier and more competitive in the landscape.

ved

unread,
Dec 18, 2016, 1:48:53 PM12/18/16
to Fat-Free Framework
From the composer installer github page:

Natively Supported Frameworks:
The following frameworks natively work with Composer and will be installed to the default vendor directory. composer/installers is not needed to install packages with these frameworks:
  • Aura
  • Symfony2
  • Yii
  • Yii2
I would argue that F3 and it's plugins fit into this category.

I'm using a few plugins with composer, and just add them to my composer.json and run composer install/update as needed. They all go into the vendor folder and I can access them directly from my apps.

And since F3 doesn't have an "official" folder structure, it doesn't seem to make any sense to make an installer to copy the plugins to a specific folder?

As I said, I'm still not convinced about the real differences and advantages on having this, but please do make your case.


Summer White

unread,
Dec 19, 2016, 12:43:40 AM12/19/16
to f3-fra...@googlegroups.com
My 2c.

I hate composer. I don't get it. I'm relatively old school coming from the old phpclasses.org website. I skipped the whole composer thing, as well as all the other auto installers. I don't even really like apt-get in debian much.

When I have to use composer, I'll put it as far away from my working directory as possible. At the moment my convention is to have a folder called "resources" that have all my external libraries. I rarely need to update and if I have to I'll do it through git.

Maybe I'm a grumpy old man but I wouldn't be too happy if any composer support was implemented into F3 that somehow dictated something about my files and folder structure. I wouldn't think so.

My 2c.

ethanpil

unread,
Dec 19, 2016, 10:42:45 AM12/19/16
to Fat-Free Framework
I was also against composer at first, but I have grown to appreciate it. Saves a lot of time and with a few tweaks you can setup F3 to work in any path. In any case the plugins should always work as they do now. This is simply a few changes to the composer.json files included with them and perhaps a PR to the composer-installer package that will teach the system to place the plugins in the right place for those of us who want to automate. It makes things a lot faster, reproducible and easier IMHO. 

FYI, I lke my F3 in /lib and my additional classes in app/utils. 

Here is my composer.json

{
 
"config": {
       
"vendor-dir": "lib"
   
},
   
"require": {
       
"bcosca/fatfree-core": "3.*",
       
"xfra35/f3-access" : "1.*",
        "leafo/scssphp": "0.5.1"
    },
   
"autoload": {
       
"psr-4": {
           
"Utils\\": "app/utils"
       
}
   
}
}

ved

unread,
Dec 19, 2016, 11:31:19 AM12/19/16
to Fat-Free Framework
Yeah composer is a must these days if your app has multiple dependencies imho.

But I use just the require statement on my composer.json. All stuff from composer goes into the vendor folder including F3 that's immediately accessible with \Base::instance() without any tweaks or installers necessary. (just call vendor/autoload.php)

This allows me to exclude the vendor folder from version control and just commit the composer.json and composer.lock files. Deployments are basically just a git checkout and composer install.

Having composer install external libs directly inside some specific folder on my app would not be ideal.

ethanpil

unread,
Dec 19, 2016, 1:00:09 PM12/19/16
to Fat-Free Framework
Although personally I don't find it as clean to use f3 plugins from the vendor folder, I'm perfectly happy if the plugins will work. I always thought they needed to be under the fatfree-core folder. Which doesnt appear to be the case. However, it seems that more specialized plugins like f3-cortex would benefit from it if they wont work from the default vendor root folder.
Reply all
Reply to author
Forward
0 new messages