twigc/src/bootstrap.php

60 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2016-07-24 20:28:49 +02:00
<?php
/**
* This file is part of twigc.
*
* @author dana <dana@dana.is>
2016-07-24 20:28:49 +02:00
* @license MIT
*/
/**
* Print an error message.
2016-07-24 20:28:49 +02:00
*
* Uses fprintf() to print to stderr if available; uses echo otherwise.
2016-07-24 20:28:49 +02:00
*
* @param string $string
* (optional) The message to print. Is passed through rtrim(); if the result
* is an empty string, only an empty line is printed; otherwise, the text
* 'twigc: ' is appended to the beginning.
2016-07-24 20:28:49 +02:00
*
* @return void
*/
function twigc_puts_error($string = '') {
$string = rtrim($string);
$string = $string === '' ? '' : "twigc: ${string}";
if ( defined('\\STDERR') ) {
fprintf(\STDERR, "%s\n", $string);
} else {
echo $string, "\n";
}
2016-08-01 02:03:27 +02:00
}
2016-07-24 20:28:49 +02:00
if ( \PHP_SAPI !== 'cli' ) {
twigc_puts_error("This tool must be invoked via PHP's CLI SAPI.");
exit(1);
2016-07-24 20:28:49 +02:00
}
(function () {
$paths = [
// Phar/repo path
__DIR__ . '/../vendor/autoload.php',
// Composer path
__DIR__ . '/../../../autoload.php',
];
foreach ( $paths as $path ) {
if ( file_exists($path) ) {
define('TWIGC_AUTOLOADER', $path);
return;
}
}
})();
if ( ! defined('\\TWIGC_AUTOLOADER') ) {
twigc_puts_error('Auto-loader is missing — try running `composer install`.');
exit(1);
2016-07-24 20:28:49 +02:00
}
require_once \TWIGC_AUTOLOADER;