Giter Club home page Giter Club logo

composer-file-loader's Introduction

Composer File Loader

Allows you to load a composer.json file just as composer would do it.

This allows you to load composer.json file without composer (so, theoretically, PHP 5.2 is enough).

Support

  • PSR-4 : YES
  • PSR-0 : YES
  • Classmap : NO
  • Files : YES

Usage

You have a composer.json file looking like this :

{
    "name": "wilkins/composer-file-loader",
    "type": "function",
    "description": "Load composer file",
    "autoload": {
        "psr-4": {
            "": "src2/",
            "RoutePlanner\\": "src/",
            "CompanyName\\PackageName\\": [
                "packages/package-folder/src/",
                "packages/package-folder1/src/"
            ]
        }
    }
}
// You load the PackageLoader
include __DIR__.'/PackageLoader.php';

// You load your packages
$loader = new PackageLoader\PackageLoader();
$loader->load(__DIR__."/vendor/project");

// You call the package classes
new CompanyName\PackageName\Machin();
new CompanyName\PackageName\Bidule();
new RoutePlanner\Truc();
new TestNoNamespace();

Testing

Just go into the root directory and run:

php test.php

If no error appears, you're good!

Contribution

Created by Thibault Taillandier from this stackoverflow question.

Please fork it to add more support

composer-file-loader's People

Contributors

agentils avatar javaskript avatar simon511000 avatar wilkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

composer-file-loader's Issues

Error: Class 'Xxx\Yyy' not found

Hi,
I try to use php-telegram-bot.
The composer file is:
https://github.com/php-telegram-bot/core/blob/master/composer.json
And it have:

    "require": {
        "php": "^5.5|^7.0",
        "ext-pdo": "*",
        "ext-curl": "*",
        "ext-json": "*",
        "ext-mbstring": "*",
        "psr/log": "^1.1",
        "monolog/monolog": "^1.24",
        "guzzlehttp/guzzle": "^6.3"
    },

So I download the file and extract unser the pat vendor/project.
The I use PHP script:

// Loading 'project' package
$loader = new PackageLoader\PackageLoader();
$loader->load(__DIR__."/psr/log");
$loader->load(__DIR__."/monolog/monolog");
$loader->load(__DIR__."/guzzlehttp/guzzle");
$loader->load(__DIR__."/longman/telegram-bot");

But when I run the php-telegram-bot code I recieve this error:
Fatal error: Class 'GuzzleHttp\Client' not found in /home/zzz/public_html/longman/telegram-bot/src/Request.php on line 269

File is: https://github.com/php-telegram-bot/core/blob/master/src/Request.php

Documentation and File placement question

Sorry, I'm sure this is a very basic question that everyone but me will know the answer to, but where exactly do all these files go?

1st. namespace PackageLoader <-- root public_html (var/www/project) ? the vendor directory with the composer directory in it? the public folder of the m-v-c pattern that is actually handling the file routing for the site? not sure?

2nd.
// You load the PackageLoader
include DIR.'/PackageLoader.php';

// You load your packages
$loader = new PackageLoader\PackageLoader();
$loader->load(DIR."/vendor/composer");

Is this at the top of all my Controller files? Core files? Module files? Is it only my "composer's autoload.php" file? Where does this go? Is it its own file? Is it actually the same as #3?

3rd.
I'm 99% sure these are the normal calls at the top of a class file call,

// You call the package classes
new CompanyName\PackageName\Machin();
new CompanyName\PackageName\Bidule();
new RoutePlanner\Truc();
new TestNoNamespace();

and can be in any class file, Controller, Module, Core, etc., yes?


When I put the PackageLoader.php in my var/www/package directory where my composer.json file was located, and then changed my composer/autoload.php to be the items in #2, it broke the site, so I was wrong on that assumption. Or maybe I need to then go and update all my class calls on my Controllers?

Sorry for the newbie questions.

Screenshot 2022-11-13 091035

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.