CodeIgniter Forums
Overwrite config file composer - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Overwrite config file composer (/showthread.php?tid=75692)



Overwrite config file composer - MatheusCastro - 03-06-2020

How do I overwrite a composer package?

For example Ion_Auth Config.php

I need a customized Config.php, which does not change when using composer update


RE: Overwrite config file composer - captain-sensible - 03-07-2020

i have not done it ; but the basics are putting your code at your repo ,then adding a reference to that source into the composer.json file. So when you do say a composer update it will check against all entries  in composer.json including your repo. Its on the composer docs. This seems to be the essence:

Code:
{
    "require": {
        "vendor/my-private-repo": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "[email protected]:vendor/my-private-repo.git"
        }
    ]
}




RE: Overwrite config file composer - MatheusCastro - 03-07-2020

It can work, thanks!


RE: Overwrite config file composer - captain-sensible - 03-07-2020

thinking about it my approach would work if you were using additional packages, that you wanted to keep updated via your repo but you want to overwrite a core Class in Config Directory say Routes.php then actually i think one of the maintainers needs to answer this one.

If you want to write your own class then thats not difficult and i'm doing that . If its one of your classes then its only a case of giving it a namespace then making sure it can be found . If your class is within a Directory , that itself is inside  app directory then for example i have a class called CheckSpam in a Directory called Andy : 
<?php namespace App\Andy;
 

class CheckSpam
{


from a controller i can make use of my class via stating this in controller:

use \App\Andy\CheckSpam;


then from a method i instantiate class and use a method:


$spamHandle = new CheckSpam();
    //CheckSpam is in app/Andy and has namespace App\Andy
        $logic = $spamHandle->filterSpam($cleanMessage);


f i do a composer update i'm pretty sure only items listed in composer.json will be updated/changed and my class's should be untouched ?