/** * The constructor * * @param array $defaultAttributes * @param ContainerObjectInterface $parent * @param Application $application * * @return void */ public function __construct(array $defaultAttributes = [], ContainerObjectInterface $parent = null, $application = null) { $object = $this; // We can use multiple applications, but, if no one is defined, we use the // first (default) if ($application == null) { $this->application = Application::$defaultApplication; } else { $this->application = $application; } if ($parent == null) { $parent = $this->application->getWindow(); } // Get the next object id $this->lazarusObjectId = $this->application->getNextObjectId(); $this->application->addObject($this); if ($this->lazarusObjectId !== 0) { if ($this instanceof VisualObjectInterface) { $parent->appendChild($this); } // Send the createObject command $this->application->sendCommand('createObject', [['lazarusClass' => $this->lazarusClass, 'lazarusObjectId' => $this->lazarusObjectId, 'parent' => $parent->getLazarusObjectId()]], function ($result) use($object, $defaultAttributes) { foreach ($defaultAttributes as $attr => $value) { $method = 'set' . ucfirst($attr); if (method_exists($object, $method)) { $object->{$method}($value); } } }); } }