Download the PHP package morningtrain/php-loader without Composer

On this page you can find all versions of the php package morningtrain/php-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-loader

PHP Loader

A simple PHP File or class loader for PHP. Built with PHP.

Table of Contents

Introduction

This package is a tool to help you initialize parts of your projects by loading in all files that match certain filename rules in a defined directory.

You may even initialize the classes contained in these files as long as they are PSR-4 compliant.

For instance, you may use this tool to load all files in a "/routes" directory or all files ending with "Block.php" and initialize all found classes that extend Block and then call init on them.

More specifically, this tool is made for, but not dependent on, the WP-Framework. Here it is useful for loading in all routes, registering all blocks and initializing all Hooks.

Getting Started

To get started install the package as described below in Installation.

To use the tool have a look at Usage

Installation

Dependencies

symfony/finder

Finder is used to find files in the directory

Usage

First create a Loader using Loader::create. This takes an absolute path to the directory you wish to load from as an argument and returns a Loader. The Loader is further configured by chaining.

In its simples form the Loader only needs a path. This will tell it to load all .php files in that directory using require

Multiple Paths

You may supply an array of full paths to Loader::create if you need to handle multiple directories;

Filename Constraints

To limit the loader to only load files with a given name use fileName(string|array $filename) See Symfoni Finder: File Name for options.

By default $fileName is *.php

Using Multiple file names

If you need to allow multiple filename formats then supply an array for Loader::fileName

Loading Classes

As long as no class related options are set on the Loader it will simply load the files.

This is useful for route files and similar.

If you have classes that you wish to load and initialize then read on!

Note: All files will be loaded even if the class requirements are not fulfilled. The Loader has no knowledge of its classes before they are loaded.

Has Method

Aborts handling a found class if it does not have a specific method.

Note: it is not necessary to specify hasMethod if call or callStatic is used.

Call Static

To call a static method on all loaded classes specify the method using Loader::callStatic($methodName)

This will call said method on every loaded class that has it. You do not need to check using Loader::hasMethod beforehand

Class or inheritance requirement

To only call methods on classes that are of a given class or extended from it use Loader::isA($className). This works the same way is ia_a($obj,$class) where $obj is the found class.

If the found class does not match the required class then the Loader will stop handling the current class and the class will never be constructed or called.

Constructing, invoking or calling

You can also construct an instance from the loaded classes, call a method on an instance or invoke an instance using the Loader.

If you use Loader::invoke or Loader::call then it is not necessary to use Loader::construct as well

Credits

Testing

License

The MIT License (MIT). Please see License File for more information.


All versions of php-loader with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/finder Version ^5.1|^6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package morningtrain/php-loader contains the following files

Loading the files please wait ....