PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 22, 2022

[FIXED] PHP Composer custom installer

 January 22, 2022     composer-php, json, php     No comments   

Issue

I'm trying to address this issue now for a long time but still could not figure out what's my mistake.

I've got two repositories I want to combine. The Application and the Framework Core.

// Application
 - composer.json
 - public/
 - CCF/
   - core/ <- here the core package should go 
   - vendor/ <- here it goes instead

Now basically I want to create a composer package that install's into CCF/core/ instead of CCF/vendor/clancats/core/etc..

So I created a custom installer at:

vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php

class ClanCatsFrameworkInstaller extends BaseInstaller
{
    protected $locations = array(
        'core'      => 'CCF/core/',
        'orbit'     => 'CCF/orbit/{$name}/',
    );
}

The composer.json of the core

{
    "name": "clancats/core",
    "description": "The ClanCatsFramework Core repository",
    "type": "clancatsframework-core",
    "license": "MIT",
    "require": {
        "php": ">=5.3",
        "composer/installers": "~1.0"
    }
}

composer.json of the application that should implement the core at CCF/core

{

    "type": "project",  
    "require": {
        "php": ">=5.3",
        "clancats/core": "dev-master"
    },
    "config": {
        "vendor-dir": "CCF/vendor"
    },
}

But after all that composer still installs the core package at /vendor/clancats/etc..

So my question is what is my mistake that composer won't install the core package to CCF/core/?

  • Added composer/installers to the requires.
  • I created a custom installer which defines the path to the core
  • Set the type of the core package to my custom one.

Another question that is spinning around my head, is my pattern wrong? I mean did i misunderstand how to use composer?

Github:

  • framework install repo: https://github.com/ClanCats/Framework
  • core repo: https://github.com/ClanCats/Core

Thanks for your help guys :)


Solution

So for everyone who runs into the same problem:

My mistake was that i didn't require the composer/installers in the main repository.

The composer installers have to be required in both repositories.

So in this case:

{
    "type": "project",  
    "require": {
        "php": ">=5.3",
        "clancats/core": "dev-master",
        "composer/installers": "~1.0"
    },
    "config": {
        "vendor-dir": "CCF/vendor"
    },
}

solves the problem.



Answered By - Mario
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing