Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php using composer autoload - own code

{
    "autoload": {
        "psr-4": {"Acme": "src/"}
    }
}
Comment

custom autoload without composer

<?php
//custom autoload without composer
$to_map = [
    'App' =>  'app/',
    'Core' => 'Core/',
];

foreach($to_map as $prefix => $base_dir)
{
    spl_autoload_register(function ($class) use ($prefix, $base_dir) {

        $base_dir = __DIR__ . "/{$base_dir}";

        $len = strlen($prefix);
        if (strncmp($prefix, $class, $len) !== 0)
        {
            return;
        }

        $relative_class = substr($class, $len);

        $file = $base_dir . str_replace('', '/', $relative_class) . '.php';

        if (file_exists($file))
        {
            require $file;
        }
    });
}
Comment

composer autoload

require __DIR__ . '/vendor/autoload.php';

$log = new MonologLogger('name');
$log->pushHandler(new MonologHandlerStreamHandler('app.log', MonologLogger::WARNING));
$log->addWarning('Foo');
Comment

php using composer autoload

require __DIR__ . '/vendor/autoload.php';

$log = new MonologLogger('name');
$log->pushHandler(new MonologHandlerStreamHandler('app.log', MonologLogger::WARNING));
$log->warning('Foo');
Comment

PREVIOUS NEXT
Code Example
Php :: create child theme in wordpress 
Php :: spatie laravel activity log 
Php :: eloquent get record older than 2 days 
Php :: laravel validation custom message 
Php :: woocommerce change add to cart button text 
Php :: wp reserved image size names 
Php :: adding data dynamically to empty array in php 
Php :: laravel collection merge 
Php :: check website ssl certificate using php 
Php :: php function uppercase first letter 
Php :: replace exact word in php 
Php :: php current time 
Php :: php italian date 
Php :: php.hello 
Php :: config file php 
Php :: wp_localize_script 
Php :: maintenance mode laravel 
Php :: how to convert youtube url to embed code in php 
Php :: showing from to in larvel pagination 
Php :: PHP strtoupper — Make a string uppercase 
Php :: convertir datetime a string en php 
Php :: using php to add numbers in html form 
Php :: php json_decode not working 
Php :: php domdocument list all elements 
Php :: cara membuat looping table dengan php 
Php :: update codeigniter 
Php :: create role spatie 
Php :: how to make a json request in php 
Php :: laravel Auth::logoutOtherDevices 
Php :: php get current page url 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =