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 :: laravel attach 
Php :: Remove revisions from Wordpress pages 
Php :: laravel Impossible to create the root directory 
Php :: today date to ago for the date in php 
Php :: laravel capsule schema datatime CURRENT_TIMESTAMP 
Php :: laravel except method 
Php :: wp add menu page and subpage 
Php :: php explode end 
Php :: how to write orderby in join query with where clause in codeigniter 
Php :: foreign key cosntraint laravel 
Php :: get user auth in laravel 
Php :: wordpress send reset password link inside wp_new_user_notification_email 
Php :: laravel eloquent update 
Php :: php sort() 
Php :: php build query from array 
Php :: Unknown column type "double" requested. Any Doctrine type that you use has to be registered with DoctrineDBALTypesType::addType 
Php :: minishlink/web-push v5.2.5 requires ext-gmp * 
Php :: javascript function in php json_encode 
Php :: laravel backup 
Php :: laravel blade components 
Php :: wordpress plugin functions exist 
Php :: php version command linux 
Php :: laravel hash 
Php :: script inside php 
Php :: php search multidimensional array for multiple values 
Php :: html in php function 
Php :: php command get ini params 
Php :: How to Add Custom Fonts to a WordPress Theme 
Php :: laravel date diff 
Php :: nested for loop in php 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =