2

I'm a little unexperienced with composer and I'm starting to use Github more and more. I'm a php developer and I an application to serve as a CMS/Backoffice of the websites I develop to my clients.

I'm using and HMVC framework and I wanted to know if its possible o deploy a module (a repository) in a specific folder with composer, and again with composer change some lines of code.

For example, I have this structure:

- app
-- modules
--- users
--- auth
-- index.php
-- configs.php
- public
-- assets

In this example, users and auth are booth a module. Imagine that I have this repository in rafaelmsantos/posts and want to deploy it on the modules folder. That part I guess is simple, or its difficult?

The second part is the following: imagine that in posts repository I have a class file like this:

<?php 
    // $this->route('posts', 'postsController->action');

    class PostsController extends appController{

        function action(){
            somestuff();
        }

    }

And when I deploy the module, I want the composer to read this file and detect that comment above class declaration and insert it into config.php that is in same level that modules folder.

Is this possible too?

Let me know some good tutorials for composer or something. Thanks, in advance.

rafaelmorais
  • 1,323
  • 2
  • 24
  • 49
  • 1
    Unfortunatelly, composer is designated for something else: it is a package manager, and not a tool for deployment. If you are looking to deploy your modules you might want to take a look into Bamboo, or search other Continuous integration tools. You might also be interested in deploying PHP apps with Apache Ant http://stackoverflow.com/questions/4226871/using-apache-ant-to-deploy-web-applications – despina Jan 19 '15 at 08:27
  • Thanks @despina, I will take a look at thoose mentioned by you. – rafaelmorais Jan 19 '15 at 11:43

1 Answers1

2

Composer have post-install-cmd and post-update-cmd events, which must be declared in composer.json file in scripts part. For example:

    {
        "scripts": {
            "post-update-cmd": "MyVendor\MyClass::postUpdate",
        }
    }
    
where 'postUpdate' is a static method, which add routes as you want.

Full info about scripts in composer

Animir
  • 1,121
  • 10
  • 23
  • With this, can I send a `post-update-cmd` to a single .php file containing the magic to add routes? (non english native :s) – rafaelmorais Jan 19 '15 at 11:52
  • 1
    "A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command-line executable command" (https://getcomposer.org/doc/articles/scripts.md#what-is-a-script-) So, you can declare script like this: `"post-update-cmd": "php /dir/to/file/script.php"` – Animir Jan 19 '15 at 12:16
  • How nice, thats exactly what I was looking for. Many thanks to you @Animir. I will give you my award in 8 hours. – rafaelmorais Jan 19 '15 at 12:17