示例#1
0
 public static function register()
 {
     ObjectManager::registerObjectRoot("/services/", new ServiceManager());
 }
示例#2
0
 public static function register()
 {
     ObjectManager::registerObjectRoot("/config/", new ConfigManager());
 }
示例#3
0
    {
        echo "Hello {$this->name}!\n";
    }
}
class HelloFactory implements IObjectManagerInterface
{
    public function omiGetObjectList($path)
    {
        return ["*"];
    }
    public function omiGetObjectProperties($path)
    {
    }
    public function omiGetObject($path)
    {
        return new TestClass($path->name);
    }
}
$foo = new TestClass("World");
// objects can be registered directly at a path, in which case the path must
// not end with a slash.
ObjMan::registerObject("local:/foo/bar/baz", $foo);
// They can also be registered via proxy classes implementing IObjectManagerInterface.
// Classes registered like this mount into the uri space.
ObjMan::registerObjectRoot("local:/hello/", new HelloFactory());
// So, we can grab our injected object
$foo2 = ObjMan::getObject("local:/foo/bar/baz");
$foo2->hello();
// Or we can query it from the factory
$foo3 = ObjMan::getObject("local:/hello/universe");
$foo3->hello();
示例#4
0
 function main()
 {
     $svc = ObjectManager::getObject($this->serviceuri);
     if (count($this->parameters) > 0) {
         switch (strtolower($this->parameters[0])) {
             case "start":
                 if ($svc->isRunning()) {
                     $this->write("Already running.\n");
                     return;
                 }
                 $this->write("Starting ... ");
                 $svc->start();
                 $this->write("Done\n");
                 break;
             case "stop":
                 if (!$svc->isRunning()) {
                     $this->write("Not running.\n");
                     return;
                 }
                 $this->write("Stopping ... ");
                 $svc->stop();
                 $this->write("Done\n");
                 break;
             case "restart":
                 $this->write("Restarting service ... ");
                 if ($svc->isRunning()) {
                     $svc->stop();
                 }
                 $svc->start();
                 $this->write("Done\n");
                 break;
             case "reload":
                 if ($svc->isRunning()) {
                     $this->write("Reloading service ... ");
                     $svc->reload();
                     $this->write("Done\n");
                 } else {
                     $this->write("Service not running.\n");
                 }
                 break;
             case "status":
                 if ($svc->isRunning()) {
                     $this->write("Running.\n");
                 } else {
                     $this->write("Not running.\n");
                 }
                 break;
             case "info":
                 $this->write("Service Information:\n\n");
                 $this->write("    Running . . . . : %s\n", $svc->isRunning() ? "Yes" : "No");
                 if ($svc->isRunning()) {
                     $this->write("    Process ID. . . : %d\n", $svc->getServicePid());
                 }
                 $this->write("    Class . . . . . : %s\n", get_class($svc));
                 $this->write("    Service ID. . . : %s\n", $svc->getServiceId());
                 $this->write("    UUID. . . . . . : %s\n", $svc->getUuid());
                 $this->write("\nProperties:\n\n");
                 $prop = ObjectManager::getObjectProperties($this->serviceuri);
                 $m = 0;
                 foreach ($prop as $k => $v) {
                     $m = max($m, strlen($k));
                 }
                 foreach ($prop as $k => $v) {
                     if (is_bool($v)) {
                         $v = $v === true ? "True" : "False";
                     } elseif (is_numeric($v)) {
                     } elseif (is_string($v)) {
                         $v = "\"{$v}\"";
                     } elseif (is_null($v)) {
                         $v = "Null";
                     }
                     $this->write("    %-{$m}s : %s\n", $k, $v);
                 }
                 $this->write("\n");
                 break;
             case "propset":
             case "propget":
             default:
                 $this->warn("No parameters or arguments found. Try -h or help.\n");
         }
     } else {
         $this->usage();
     }
 }
示例#5
0
<?php

require_once "../../share/include/cherryphp";
use Cherry\Core\ObjectManager as ObjMan;
use Cherry\Core\ServiceManager as SvcMan;
use Cherry\Core\ServiceInstance;
SvcMan::register();
class TestService extends ServiceInstance
{
    public $serviceid = "info.noccylabs.testservice";
    protected $flags = ServiceInstance::SVC_RESTART;
    function servicemain()
    {
        for ($s = 0; $s < 5; $s++) {
            usleep(100000);
        }
    }
    function onShutdown()
    {
    }
}
SvcMan::addServiceInstance(new TestService("/tmp/testservice.pid"));
$svc = ObjMan::getObject("local:/services/info.noccylabs.testservice#0");
if ($svc->isRunning()) {
    $svc->stop();
} else {
    $svc->start();
}
示例#6
0
 function servicemain()
 {
     // Set up the httpd. Will be cloned for each new instance.
     $http = new \Higgs\HttpServer();
     /*
             $http->addExtension(new \Higgs\Extensions\Misc\AddHeader([
                 "header" => "x-foo",
                 "value" => "Hello World"
             ]));
     */
     $cfg = ObjMan::getObject("local:/config/higgs");
     $exts = $cfg->query("/httpd/server[default]/extension");
     foreach ($exts as $ext) {
         $cn = \Utils::getClassFromDotted($ext[0]);
         class_exists($cn);
     }
     foreach ($exts as $ext) {
         $cn = \Utils::getClassFromDotted($ext[0]);
         if (class_exists($cn)) {
             $ext = new $cn($ext->getAttributes());
             $http->addExtension($ext);
         } else {
             $this->warn("Could not load extension '{$ext[0]}'");
         }
     }
     //$ctrl = new \Higgs\HttpControl();
     $server = new SocketServer();
     $ports = $cfg->query("/httpd/server[default]/listen");
     foreach ($ports as $ep) {
         $endpoint = $ep[0];
         if ($ep->hasAttribute("certificate")) {
             $cert = new Certificate("server.pem");
             $this->debug("Using certificate %s", "server.pem");
             $info = $cert->getCertificateInfo();
             list($vfrom, $vto) = $cert->getValidity();
             $this->debug("    Issued to:    %s", $info["name"]);
             $this->debug("    Issuer:       %s (%s)", $info["issuer"]["O"], $info["issuer"]["OU"]);
             $this->debug("    Hash:         0x%s", $info["hash"]);
             $this->debug("    Valid from:   %s", $vfrom);
             $this->debug("    Valid until:  %s", $vto);
             if ($cert->isSelfSigned()) {
                 $this->warn("Warning! The certificate in use is self-signed. Consider getting a proper certificate for production use.");
                 $this->warn("HSTS by design does not allow self-signed certificates. Enabling HSTS will not work.");
             }
             $server->addListener($endpoint, $http, $cert);
         } else {
             $server->addListener($endpoint, $http);
         }
     }
     /*
     $server->addListener("tcp://127.0.0.1:9700", $http);
     $server->addListener("ssl://127.0.0.1:9701", $http, $cert);
     $server->addListener("tcp://127.0.0.1:9799", $http);
     */
     while ($server->process()) {
         usleep(5000);
         if ($this->stop) {
             break;
         }
     }
 }