php-spark/runtime/SparkPlug.php

33 lines
872 B
PHP

<?php
use Spark\SparkApplication;
abstract class SparkPlug
{
abstract public function load();
public function getPlugin(string $name)
{
return SparkApplication::$instance->getPluginManager()->getPlugin($name);
}
function get_resource(string $name) {
return SparkApplication::$instance->getResourceManager()->getNamedResource($name);
}
function read_config($file=null) {
if (!$file) return;
$abs = get_environment()->getConfigDirectory() . "/" . $file;
if (!file_exists($abs)) {
//fprintf(STDERR, "warning: Can't read config file %s\n", $abs);
return [];
}
return (array)json_decode(file_get_contents($abs), true);
}
function getProjectDirectory()
{
return SparkApplication::$instance->getEnvironment()->getProjectDirectory();
}
}