honeybee/trellis

View on GitHub
src/CodeGen/ClassBuilder/templates/EntityType/BaseEmbeddedEntityType.twig

Summary

Maintainability
Test Coverage
<?php
/*
 * AUTOGENERATED CODE - DO NOT EDIT!
 *
 * This base class was generated by the Trellis library and
 * must not be modified manually. Any modifications to this
 * file will be lost upon triggering the next automatic
 * class generation.
 *
 * If you are looking for a place to alter the behaviour of
 * the '{{ type_name }}' type please see the skeleton
 * class '{{ class_name }}'. Modifications to the skeleton
 * file will prevail any subsequent class generation runs.
 *
 * To define new attributes or adjust existing attributes and their
 * default options modify the schema definition file of
 * the '{{ type_name }}' type.
 *
 * @see https://github.com/honeybee/trellis
 */

namespace {{ namespace }};

use {{ parent_implementor }};
{% for namespace in extra_namespaces %}
use {{ namespace }};
{% endfor %}
use Trellis\Common\Options;
use Trellis\Runtime\EntityTypeInterface;
use Trellis\Runtime\Attribute\AttributeInterface;

/**
 * Serves as the base class to the '{{ type_name }}' type skeleton.
 */
abstract class {{ class_name }} extends {{ parent_class_name }}
{
    /**
     * Creates a new '{{ class_name }}' instance.
     */
    public function __construct(EntityTypeInterface $parent = null, AttributeInterface $parent_attribute = null)
    {
        parent::__construct(
            '{{ type_name }}',
            [
            {%- for attribute in attributes %}
                {%- if attribute.options|length > 0 %}

                new {{ attribute.class_name }}(
                    '{{ attribute.name }}',
                    $this,
                    {{ attribute.options|raw }},
                    $parent_attribute
                ),

                {%- else %}

                new {{ attribute.class_name }}('{{ attribute.name }}', $this, [], $parent_attribute),

                {%- endif %}
            {%- endfor %}

            ]
            {%- if options|length > 0 %},
            new Options(
                {{ options|raw }}
            ),
            {%- else %}
            [],
            {%- endif %}
            $parent,
            $parent_attribute
        );
    }

    /**
     * Returns the EntityInterface implementor to use when creating new entities.
     *
     * @return string Fully qualified name of an EntityInterface implementation.
     */
    public static function getEntityImplementor()
    {
        return {{ entity_implementor|raw }};
    }
}