Gui\Components\Object::__construct PHP Метод

__construct() публичный Метод

The constructor
public __construct ( array $defaultAttributes = [], Gui\Components\ContainerObjectInterface $parent = null, Application $application = null ) : void
$defaultAttributes array
$parent Gui\Components\ContainerObjectInterface
$application gui\Application
Результат 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);
                    }
                }
            });
        }
    }