Пример #1
0
    /**
     * @param array|stdClass|Traversable $data
     * @return HierarchicalInputFilter
     * @throws InvalidArgumentException
     */
    public function setData($data)
    {
        if ($data instanceof stdClass) {
            $data = Utils::toArray($data);
        }

        // set data and prevent validation of (arrays of) objects by removing the nested input filter
        // note: the actual input filter is not removed because otherwise there would be no container
        //       for the data. setting the input filter to not required is also not necessary because
        //       the data is already set so it's always valid.
        foreach ($this->nestedInputFilters as $name => $nestedInputFilter) {
            if (isset($data[$name])) {
                if (is_object($data[$name]) ||
                   (is_array($data[$name]) && (
                       $this->isContainingObjects($data[$name]) ||
                       (isset($data[$name]['id']) ||
                       (isset($data[$name][0]) && isset($data[$name][0]['id'])))
                   ))
                ) {
                    $this->removeNestedInputFilter($name);
                } else {
                    $nestedInputFilter->setData($data[$name]);
                }
            } else {
                $nestedInputFilter->setData([]);
            }
        }

        parent::setData($data);

        return $this;
    }
Пример #2
0
    /**
     * Overridden to allow for using stdClass
     *
     * @param array|Traversable|stdClass $data
     * @return InputFilterInterface
     * @throws InvalidArgumentException
     */
    public function setData($data)
    {
        if ($data instanceof stdClass) {
            $data = Utils::toArray($data);
        }
        parent::setData($data);

        return $this;
    }