Esempio n. 1
0
 public static function getService(ArrayObject $config, Loops $loops)
 {
     if ($options = $config->toArray()) {
         return new Docker(new DockerClient($options));
     }
     return new Docker();
 }
Esempio n. 2
0
 public function setValue($value)
 {
     if (is_array($value)) {
         $value = new ArrayObject($value);
     }
     $current = $this->subform->getFormElements();
     foreach (array_keys($current) as $key) {
         $this->subform->offsetUnset($key);
     }
     if ($value instanceof ArrayObject) {
         $values = $value->toArray();
     } elseif ($value instanceof Traversable) {
         $values = iterator_to_array($value);
     } else {
         $values = (array) $value;
     }
     static $meh = 0;
     if ($meh++ > 40) {
         throw new \Exception("Meh");
     }
     foreach ($values as $k => $v) {
         $element = array_key_exists($k, $current) ? $current[$k] : Misc::deepClone($this->newelement);
         $element->setValue($v);
         $value->offsetSet($k, $element->getValue(FALSE));
         $this->subform->offsetSet($k, $element);
     }
     return parent::setValue($value);
 }
 public function testFromArrayNested()
 {
     $array = ArrayObject::fromArray(["a" => "b", "c" => ["d" => "e"]]);
     $this->assertInstanceOf("Loops\\ArrayObject", $array);
     $this->assertInstanceOf("Loops\\ArrayObject", $array["c"]);
     $this->assertSame("e", $array["c"]["d"]);
 }
Esempio n. 4
0
 /**
  * Creates an "Loops\ArrayObject" from a normal PHP array.
  * Nested arrays will recursively converted.
  *
  * @param array $input The input array
  * @return Loops\ArrayObject The input array as a "Loops\ArrayObject".
  */
 public static function fromArray(array $input)
 {
     $input = array_map(function ($value) {
         return is_array($value) ? ArrayObject::fromArray($value) : $value;
     }, $input);
     return new ArrayObject($input);
 }
Esempio n. 5
0
 public function __construct($array = [])
 {
     foreach ($array as $key => $value) {
         if (!is_array($value)) {
             continue;
         }
         $array[$key] = new ArrayConfig($value);
     }
     parent::__construct($array);
 }
 public function filter($value)
 {
     if (is_array($value)) {
         $value = ArrayObject::fromArray($value);
     }
     if (is_null($value)) {
         $value = new ArrayObject();
     }
     return $value;
 }
Esempio n. 7
0
 public function saveToSession()
 {
     $this->initFromSession();
     //new session object
     $session = new ArrayObject();
     //initialize object from values
     foreach ($this->getSessionVars() as $key) {
         $session->offsetSet($key, $this->{$key});
     }
     //fire session save event - may adjust the values
     $this->fireEvent("Session\\onSave", [$session]);
     //set in the session service
     $this->getLoops()->getService("session")->set($this->sessionid, $session);
 }
Esempio n. 8
0
<?php

use Loops\ArrayObject;
$c["test"] = "test";
$c["session"]["plugin"] = "Test";
$c["config_test_service"]["a"] = "c";
$c["config_test_service"]["other"] = "other";
// keep quiet (stderr logging is enabled on default)
$c["logger"]["plugin"] = "";
return ArrayObject::fromArray($c);
Esempio n. 9
0
 public function testCreateServiceMergingConfig()
 {
     $name = uniqid();
     $loops = new Loops(ArrayObject::fromArray([$name => ["a" => "b"]]));
     $loops->registerService($name, "LoopsTestServiceMock");
     $service = $loops->createService($name, NULL, FALSE);
     $this->assertInstanceOf("LoopsTestServiceMock", $service);
     $this->assertSame("a", $service->a);
     $service = $loops->createService($name, NULL, TRUE);
     $this->assertInstanceOf("LoopsTestServiceMock", $service);
     $this->assertSame("b", $service->a);
     $service = $loops->createService($name, ArrayObject::fromArray(["a" => "c"]), TRUE);
     $this->assertInstanceOf("LoopsTestServiceMock", $service);
     $this->assertSame("c", $service->a);
 }
Esempio n. 10
0
 public function __construct(Form $form, $array = [], $flags = StdArrayObject::ARRAY_AS_PROPS, $iterator_class = "ArrayIterator")
 {
     parent::__construct($array, $flags, $iterator_class);
     self::$forms[spl_object_hash($this)] = $form;
 }
Esempio n. 11
0
 /**
  * Creates a new instance of a service
  *
  * @param $name The service name
  * @param array $config
  * @return Loops\Service\ServiceInterface The new service
  */
 public function createService($name, ArrayObject $config = NULL, $merge_into_config = FALSE)
 {
     if ($merge_into_config) {
         $service_config = $this->config->offsetExists($name) ? $this->config->offsetGet($name) : new ArrayObject();
         if (is_array($service_config)) {
             $service_config = ArrayObject::fromArray($service_config);
         }
         if ($config) {
             $service_config->merge($config);
         }
     } else {
         $service_config = $config ?: new ArrayObject();
     }
     if (!$this->hasService($name)) {
         throw new Exception("Service '{$name}' does not exist.");
     }
     $service = $this->services[$name];
     if (array_key_exists("classname", $service)) {
         $reflection = new ReflectionClass($service["classname"]);
         $params = new ArrayObject($service["params"]);
         $params->merge($service_config);
         if ($reflection->implementsInterface("Loops\\ServiceInterface")) {
             return call_user_func_array([$service["classname"], "getService"], [$params, $this]);
         } else {
             $params->offsetSet("loops", $this);
             return Misc::reflectionInstance($service["classname"], $params);
         }
     }
     if (array_key_exists("callback", $service)) {
         $params = new ArrayObject($service["params"]);
         $params->merge($service_config);
         return call_user_func_array($service["callback"], $params->toArray());
     }
     if (array_key_exists("object", $service)) {
         return $service["object"];
     }
 }
Esempio n. 12
0
 function testFormValue()
 {
     $app = new WebApplication(__DIR__ . "/app", "/");
     $value = new ArrayObject(["test" => "123abc"]);
     $form = new SimpleTestForm($value);
     $formvalue = $form->getFormValue();
     $this->assertInstanceOf("Loops\\Form\\Value", $formvalue);
     $this->assertSame($value->toArray(), $formvalue->toArray());
     $this->assertSame($form, $formvalue->getForm());
 }