2016-07-24 20:28:49 +02:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This file is part of twigc.
|
|
|
|
|
*
|
2018-06-02 08:47:11 +02:00
|
|
|
|
* @author dana <dana@dana.is>
|
2016-07-24 20:28:49 +02:00
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2018-06-02 08:47:11 +02:00
|
|
|
|
* Print an error message.
|
2016-07-24 20:28:49 +02:00
|
|
|
|
*
|
2018-06-02 08:47:11 +02:00
|
|
|
|
* Uses fprintf() to print to stderr if available; uses echo otherwise.
|
2016-07-24 20:28:49 +02:00
|
|
|
|
*
|
|
|
|
|
* @param string $string
|
2018-06-02 08:47:11 +02:00
|
|
|
|
* (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 = '') {
|
2018-06-02 08:47:11 +02:00
|
|
|
|
$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' ) {
|
2018-06-02 08:47:11 +02:00
|
|
|
|
twigc_puts_error("This tool must be invoked via PHP's CLI SAPI.");
|
|
|
|
|
exit(1);
|
2016-07-24 20:28:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-02 08:47:11 +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
|
|
|
|
}
|
|
|
|
|
|
2018-06-02 08:47:11 +02:00
|
|
|
|
require_once \TWIGC_AUTOLOADER;
|