-2

I'm making a request handler for php, which will route requests to specific files on the server. I have a .htaccess file that routes every request to DOCUMENT_ROOT/Server/handleRequest.php, which then handles everything else from there. To make this work, I copy the .htaccess file and Server folder to the root folder for my site.

I've been successful in getting composer to install my project to the vendor directory under vendor/JakarCo/PHP-Request-Handler. I would like all the files (at the very least, the .htaccess file) to be installed directly into the site's document root folder (one level above the vendor folder).

I am trying to use oomphinc/composer-installers-extender to set a custom path, and it's not working, and I can't figure out how to fix it.

The composer.json in the request handler is

{
    "name": "JakarCo/PHP-Request-Handler",
    "description": "php request handler",
    "type": "library",
    "license": "proprietary",
    "require": {
        "php": "^5.3.6 || ^7.0",
        "oomphinc/composer-installers-extender": "@dev"
    },
    "extra": {
        "installer-types": ["library"],
        "installer-paths": {
            "my/path/": ["JakarCo/PHP-Request-Handler/"],
            "path/to/libraries/JakarCo/": ["type:library"]
        }  
    }
}

The composer.json for the project that is including the request handler is:

{
    "repositories": [
        {
            "url": "https://github.com/JakarCo/PHP-Request-Handler",
            "type": "vcs"
        }
    ],
    "require": {
        "JakarCo/PHP-Request-Handler": "dev-master"
    }
}

When I run composer update from from the site's root folder, it runs successfully (now with nothing to change). So I deleted the vendor folder and the composer.lock file and ran composer install and had three successful installs, of composer/installer, the oomphinc one, and mine. But mine is still going into the vendor/JakarCo/PHP-Request-Handler, when the Server folder and .htaccess files need to go into the site's root folder.

I suspect my problem is with installer-paths, but I can't figure out how it's supposed to be. Also, I'm probably not supposed to use @dev for the oomphinc version, but I don't know what else to put.

I'm experienced with PHP, but very out of practice, and am new to using composer and git.

Reed
  • 14,703
  • 8
  • 66
  • 110
  • Also, the request handler is a very early version and I know there's much to improve. If I can't get the composer installing to work, then I can do a manual copy-paste of the .htaccess and use namespaced classes for the other documents and make use of the autoloader. But that's stuff I'd rather do later. – Reed Sep 19 '18 at 15:31
  • Why you're installing it as dependency/library, if it should work as a project? – rob006 Sep 20 '18 at 07:41
  • @rob006 I tried setting the type as project, but it didn't seem to do anything differently. The documentation really didn't clear anything up. I'm doing some more reading now, though. I don't really understand how it uses the different types. – Reed Sep 21 '18 at 01:41

1 Answers1

1

UPDATE

This turned out bad. Very bad lol. The composer.json from the request handler project overwrote the composer.json file that i was using to include it.

--

I wrote my own installer using https://getcomposer.org/doc/articles/custom-installers.md as a guide, just copy-pasting what they had.

Important notes: The composer.json for the site I'm working on requires a pointer to the Request Handler and a pointer to the Request Handler installer as below. I tried to put the pointer to the installer in the request handler project, but I later read that the repositories part is only read by the root composer. That is, the composer.json file in the working directory from which you call composer install/composer update. Alternatively, the installer project can be added to packagist then the Request Handler project would be able to require it directly.

I had a hard time getting the installer to start working. That's because the $packageType passed to supports() in the installer is lower case, and the type i specified includes uppercase, so the return $packageType === 'JakarCo-request-installer turned into `return $packageType == strtolower('JakarCo-request-installer').

Another problem I had was composer telling me that the directory name returned by 'getInstallPath' could not be empty, when I was doing return '/'. I changed to return ./ and still had problems. I did composer clear-cache then rm -rf vendor then rm composer.lock then re-rann composer install and now it is working.

This could all be much better, but for now I'm just needing the basic functionality. I will improve the quality of my code later. I'm new to composer and it's all kind of overwhelming, and I find the documentation hard to follow.

{
  "repositories": [
      {
        "type": "vcs",
        "url": "https://github.com/JakarCo/PHP-Request-Handler"
      },
      {
        "type": "vcs",
        "url": "https://github.com/JakarCo/PHP-Request-Handler-Installer"
      }
  ],
  "require": {
    "JakarCo/PHP-Request-Handler": "dev-master",
    "JakarCo/PHP-Request-Handler-Installer": "dev-master"
  }
}

So, the repositories had to be defined in the site project. Defining the repositories in the Request Handler project did nothing and then Request-handler-installer could not be found, because composer does not recursively function in that matter, unless your projects are on packagist, in which case you do not define repositories. Annoying, but workable.

Reed
  • 14,703
  • 8
  • 66
  • 110