<commit_before><?php

namespace FlexPress\Components\Layouts;

class Controller
{

    // =============
    // ! PROPERTIES
    // =============

    /**
     * @var array
     */
    protected $layouts;

    // ==============
    // ! CONSTRUCTOR
    // ==============

    /**
     * @param array $layouts
     * @throws \RuntimeException
     */
    public function __construct(array $layouts)
    {

        $this->layouts = array();

        if (!empty($layouts)) {

            foreach ($layouts as $layout) {

                if (!$layout instanceof AbstractLayout) {

                    $message = "One or more of the layouts you have passed to ";
                    $message .= get_class($this);
                    $message .= " does not implement the AbstractLayout interface.";
                    throw new \RuntimeException($message);

                }

                $this->layouts[$layout->getName()] = $layout;

            }

        }

    }

    // ==================
    // ! METHODS
    // ==================

    /**
     *
     * Used to output layouts for the site(setup in options)
     *
     * @param string $fieldName
     * @author <NAME>
     *
     */
    public function theSiteLayouts($fieldName = 'fpt_layouts')
    {
        if ($layoutObjects = $this->getLayoutObjects($fieldName, "options")) {
            $this->outputLayouts($layoutObjects);
        }
    }

    /**
     *
     * Used to output the layouts got the current page
     *
     * @param string $fieldName
     * @param bool $postID
     * @author <NAME>
     */
    public function thePageLayouts($fieldName = 'fpt_layouts', $postID = false)
    {
        if ($layoutObjects = $this->getLayoutObjects($fieldName, $postID)) {
            $this->outputLayouts($layoutObjects);
        }
    }

    /**
     *
     * Given a array of layouts it will call getMarkup on them,
     * and output the markup
     *
     * @param $layoutObjects
     * @return bool
     * @author <NAME>
     *
     */
    protected function outputLayouts($layoutObjects)
    {
        if (!is_array($layoutObjects)
            || empty($layoutObjects)
        ) {
            return;
        }

        foreach ($layoutObjects as $layout_object) {

            $layout_object->getMarkup();

        }
    }

    /**
     *
     * Calls get_field for the given fieldname and postID. Then maps the data returned to the actual
     * layouts class
     *
     * @param string $acf_field_name
     * @param bool $post_id
     * @return array
     * @author <NAME>
     *
     */
    public function getLayoutObjects($acf_field_name = 'fpt_layouts', $post_id = false)
    {

        if (!$post_id) {
            $post_id = get_the_ID();
        }

        // No fieldGroups, return false
        if (!$layoutFields = get_field($acf_field_name, $post_id)) {
            return false;
        }

        // Not an array of array is empty, return false
        if (!is_array($layoutFields)
            || empty($layoutFields)
        ) {
            return false;
        }

        $layoutsObjects = array();<commit_msg>removing default field name<commit_after><?php

namespace FlexPress\Components\Layouts;

class Controller
{

    // =============
    // ! PROPERTIES
    // =============

    /**
     * @var array
     */
    protected $layouts;

    // ==============
    // ! CONSTRUCTOR
    // ==============

    /**
     * @param array $layouts
     * @throws \RuntimeException
     */
    public function __construct(array $layouts)
    {

        $this->layouts = array();

        if (!empty($layouts)) {

            foreach ($layouts as $layout) {

                if (!$layout instanceof AbstractLayout) {

                    $message = "One or more of the layouts you have passed to ";
                    $message .= get_class($this);
                    $message .= " does not implement the AbstractLayout interface.";
                    throw new \RuntimeException($message);

                }

                $this->layouts[$layout->getName()] = $layout;

            }

        }

    }

    // ==================
    // ! METHODS
    // ==================

    /**
     *
     * Used to output layouts for the site(setup in options)
     *
     * @param string $fieldName
     * @author <NAME>
     *
     */
    public function theSiteLayouts($fieldName)
    {
        if ($layoutObjects = $this->getLayoutObjects($fieldName, "options")) {
            $this->outputLayouts($layoutObjects);
        }
    }

    /**
     *
     * Used to output the layouts got the current page
     *
     * @param string $fieldName
     * @param bool $postID
     * @author <NAME>
     */
    public function thePageLayouts($fieldName, $postID = false)
    {
        if ($layoutObjects = $this->getLayoutObjects($fieldName, $postID)) {
            $this->outputLayouts($layoutObjects);
        }
    }

    /**
     *
     * Given a array of layouts it will call getMarkup on them,
     * and output the markup
     *
     * @param $layoutObjects
     * @return bool
     * @author <NAME>
     *
     */
    protected function outputLayouts($layoutObjects)
    {
        if (!is_array($layoutObjects)
            || empty($layoutObjects)
        ) {
            return;
        }

        foreach ($layoutObjects as $layout_object) {

            $layout_object->getMarkup();

        }
    }

    /**
     *
     * Calls get_field for the given fieldname and postID. Then maps the data returned to the actual
     * layouts class
     *
     * @param string $acf_field_name
     * @param bool $post_id
     * @return array
     * @author <NAME>
     *
     */
    public function getLayoutObjects($acf_field_name, $post_id = false)
    {

        if (!$post_id) {
            $post_id = get_the_ID();
        }

        // No fieldGroups, return false
        if (!$layoutFields = get_field($acf_field_name, $post_id)) {
            return false;
        }

        // Not an array of array is empty, return false
        if (!is_array($layoutFields)
            || empty($layoutFields)
        ) {
            return false;
        }

        $layoutsObjects = array();
{'fraction_non_alphanumeric': 0.14144202663202338, 'fraction_numerical': 0.0, 'mean_word_length': 1.694225721784777, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7383828', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1687, 'n_words': 411}