Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2/**
3 * When strauss is installed via Composer, this will help load the aliases file.
4 *
5 * When `composer install --no-dev` is run, Strauss won't be installed and this file won't exist to load
6 * `autoload_aliases.php`. This is good – we don't want to load the aliases file in production or we end up
7 * fixing the namespace collision issue for ourselves but preserving it for other packages.
8 *
9 * This file tries to read the project composer.json file to find the target directory. If it can't find it, it
10 * assumes the default "vendor-prefixed".
11 *
12 * @package brianhenryie/strauss
13 */
14
15$autoloadAliasesFilepath = realpath(__DIR__ . '/../../composer/autoload_aliases.php');
16if (file_exists($autoloadAliasesFilepath)) {
17    $targetDirectoryFromComposerExtra = function () {
18        $composerJsonFilepath = realpath(__DIR__ . '/../../../composer.json');
19        if (file_exists($composerJsonFilepath)) {
20            $composerJson = json_decode(file_get_contents($composerJsonFilepath), true);
21            if (isset($composerJson['extra']['strauss']['target_directory'])
22                &&
23                is_dir(realpath(__DIR__ . '/../../../'.$composerJson['extra']['strauss']['target_directory']))
24            ) {
25                return $composerJson['extra']['strauss']['target_directory'];
26            }
27        }
28        return null;
29    };
30
31    $autoloadTargetFilepath = sprintf(
32        "%s/%s/autoload.php",
33        getcwd(),
34        $targetDirectoryFromComposerExtra() ?? "vendor-prefixed"
35    );
36    if ($autoloadTargetFilepath !== realpath(__DIR__ . '/../../autoload.php') && file_exists($autoloadTargetFilepath)) {
37        require_once $autoloadTargetFilepath;
38    }
39    unset($autoloadTargetFilepath);
40
41    require_once $autoloadAliasesFilepath;
42}
43unset($autoloadAliasesFilepath,);