GithubHelp home page GithubHelp logo

guoyu07 / robot-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nette/robot-loader

0.0 0.0 0.0 162 KB

๐Ÿ€ RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.

Home Page: https://nette.org

License: Other

PHP 100.00%

robot-loader's Introduction

RobotLoader: comfortable autoloading

Downloads this Month Build Status Coverage Status Latest Stable Version License

Introduction

RobotLoader is a tool that gives you comfort of automated class loading for your entire application including third-party libraries.

  • get rid of all require
  • only necessary scripts are loaded
  • requires no strict file naming conventions
  • allows more classes in single file

RobotLoader is extremely comfortable and addictive!

So we can forget about those famous code blocks:

require_once 'Utils/Page.php';
require_once 'Utils/Style.php';
require_once 'Utils/Paginator.php';
...

Like the Google robot crawls and indexes websites, RobotLoader crawls all PHP scripts and records what classes and interfaces were found in them. These records are then saved in cache and used during all subsequent requests.

Documentation can be found on the website.

Installation

The recommended way to install is via Composer:

composer require nette/robot-loader

It requires PHP version 5.6 and supports PHP up to 7.2.

Usage

You just need to specifiy what directories to index and where to save the cache:

$loader = new Nette\Loaders\RobotLoader;

// Add directories for RobotLoader to index
$loader->addDirectory(__DIR__ . '/app');
$loader->addDirectory(__DIR__ . '/libs');

// And set caching to the 'temp' directory
$loader->setTempDirectory(__DIR__ . '/temp');
$loader->register(); // Run the RobotLoader

And that's all. From now on, you don't need to use require. Great, isn't it?

When RobotLoader encounters duplicate class name during indexing, it throws an exception and informs you about it.

The $loader->setAutoRefresh(true or false) determines whether RobotLoader should reindex files if asked for nonexistent class. This feature should be disabled on production server.

If you want RobotLoader to skip some directory, use $loader->excludeDirectory('temp').

robot-loader's People

Contributors

dg avatar fprochazka avatar jantvrdik avatar jsmitka avatar kravco avatar majkl578 avatar milo avatar vasekpurchart avatar vlastavesely avatar vojtech-dobes avatar vrana avatar

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.