It assumes that $data is an array
@param mixed $data
@param array $failed
@return bool
@throws \Exception
160261
protected function checkFormat($data = null, &$failed = array()) {
        if (is_null($data)) $data = $this->data;

        if ($this->format === "array") {
            $count = count($data);
            $countRange = new IntegerS( );
            $countRange->setRange("[" . $this->minimumItemNumber . "," . $this->maximumItemNumber . "]");

            return $countRange->check($count);// no need to run again is_array
        }

        if (is_string($this->format)) {
            $valid = true;
            foreach ($data as $key=>$value) {
                if (!$this->checkValue($value, $this->format, false, $valueFailed)) {
                    $failed[$key] = $valueFailed;
                    $valid = false;
                }
            }
            $count = count($data);
            $countRange = new IntegerS( );
            $countRange->setRange("[" . $this->minimumItemNumber . "," . $this->maximumItemNumber . "]");

            return $valid && $countRange->check($count);
        }

        /**
         * countStrict behavior:
         *  - if $data has more entries than the $format, it's up to $countStrict
         *  - if $data has the same entries as the $format, ok
         *  - if $data has less entries than the $format, the string "null" is searched
         *      in $format
         */
        if (!$this->getNull() && $this->isCountStrict()){
            if (count($data) > count($this->format) ||
                (count($data) < count($this->format) && !$this->searchNullItems())) {
                return false;
            }
            // else: ok
        }

        $associativeData = ArrayS::isAssociative($data);
        $associativeFormat = ArrayS::isAssociative($this->format);

        if ($associativeData == $associativeFormat) {
            $valid = true;
            foreach ($this->getFormat() as $key=>$value) {
                $testData = isset($data[$key]) ? $data[$key] : null;
                if (!$this->checkValue($testData, $value, false, $valueFailed)) {
                    $failed[$key] = $valueFailed;
                    $valid = false;
                }
            }
            return $valid;
        } else {
            return false;
        }
    }
544051
public function failed($e)
    {
        $this->prepareData();

        $handler = Container::getInstance()->make($this->class);

        $parameters = array_merge($this->data, [$e]);

        if (method_exists($handler, 'failed')) {
            call_user_func_array([$handler, 'failed'], $parameters);
        }
    }
645880
public function update(array $data)
    {
        try
        {
            if ( $this->validator->with($data)->validForUpdate() )
            {
                $this->users->update($data['id'], $this->validator->getData());
                return true;
            }
        }
        catch (LoginRequiredException $e)
        {
            $this->validator->add('LoginRequiredException',$e->getMessage());
        }
        catch (PasswordRequiredException $e)
        {
            $this->validator->add('PasswordRequiredException',$e->getMessage());
        }
        catch (UserExistsException $e)
        {
            $this->validator->add('UserExistsException',$e->getMessage());
        }

        return false;
    }
876304
public function convertFailedToDelete(array $data = null)
    {
        $result = new FailedToDeleteData();

        if (empty($data)) {
            return $result;
        }

        $result->setIds(array_map('strval', $data[JSONConstants::JSON_FAILEDTODELETE_ID] ?? []));
        $result->setExtensions($this->convertExtension($data, JSONConstants::getFailedToDeleteKeys()));

        return $result;
    }
867389
public function failed(array $data, $e)
    {
        $handler = $this->container->make($data['class']);

        $parameters = array_merge(unserialize($data['data']), [$e]);

        if (method_exists($handler, 'failed')) {
            call_user_func_array([$handler, 'failed'], $parameters);
        }
    }
1001190
public static function toArray($data, $recursive = false)
    {
        // Ensure the input data is an array.
        if (\is_object($data)) {
            if ($data instanceof \Traversable) {
                $data = iterator_to_array($data);
            } elseif (method_exists($data, 'toArray')) {
                $data = $data->toArray();
            }
        } else {
            $data = (array)$data;
        }

        if ($recursive) {
            foreach ($data as &$value) {
                if (\is_array($value) || \is_object($value)) {
                    $value = static::toArray($value, $recursive);
                }
            }
        }

        return $data;
    }
918245
public function save($data=array())
    {

		if (empty($data)) {
			throw new \Exception( "User data is missing" );
		}
        $data = (object) $data;

		if ((!isset($data->email) || empty($data->email))) {
			throw new \Exception( "Email is required" );
		}
		if ((!isset($data->password) || empty($data->password)) && !isset($data->id)) {
			throw new \Exception( "Password is required" );
		}

		$new  = false;
		if (isset($data->id)) {
			$entity = $this->getById($data->id);
		} else {
			$entity = new entity();
			$new    = true;
		}
		if (isset($data->name)) {
			$entity->setName($data->name);
		}
		if (isset($data->email)) {
			$entity->setEmail($data->email);
		}
		if (isset($data->password)) {
			$entity->setPassword($this->getSalted($data->password));
		} elseif (isset($data->new_password)){
			$entity->setPassword($this->getSalted($data->new_password));
		}
		if (empty($data->role)) {
			$data->role = $this->_getDefaultRole();
		}
		$entity->setRole($data->role);
		if (isset($data->gateway_customer_id)) {
			$entity->setGatewayCustomerId($data->gateway_customer_id);
		}

		if ($new) {
			$this->_em->persist($entity);
		} else {
			$this->_em->merge($entity);
		}

		// Save the entity
		try {
			$eventType = $new ? Log::EVENT_CREATE : Log::EVENT_UPDATE;
			if(isset($data->new_password)){
				$eventType = Log::EVENT_PASSWORD;
				unset($data->new_password);
			}
			unset($data->password);

			$this->createUserEventLog($eventType, $data);
			$this->_em->flush();
			$this->setEntity($entity);

			return $entity->getId();

		} catch ( \Doctrine\DBAL\Exception\UniqueConstraintViolationException $e ) {
			// \Erdiko::log(\Psr\Log\LogLevel::INFO, 'UniqueConstraintViolationException caught: '.$e->getMessage());
			throw new \Exception( "Can not create user with duplicate email" );
		}

		return null;
	}
900246
public function success(array $data = null)
    {
        $codes = $this->code;
        $code = $codes::SUCCESS;

        return $this->output($code, $this->codeMessage($code), $data);
    }
280851
public function canAny($permissions, &$failed = null)
    {
        $permissions = is_array($permissions) ? collect($permissions) : $permissions;

        $failed = $permissions->reject(function ($permission) {
            return $this->can($permission);
        })->values();

        return $permissions->count() !== $failed->count();
    }
1142595
public function update(array $data)
    {
        $id = (int) empty($data['id']) ? 0 : $data['id'];
        if ($id <= 0) {
            throw new Exception('Required field id');
        }
        $person_id = empty($data['person_id']) ? 0 : (int) $data['person_id'];
        unset($data['id'], $data['person_id']);
        return $this->rest->put('people/' .
           ($person_id ? $person_id . '/' : '') .  "$this->action/$id", $data);
    }
1303268
public function render($view, $data = [])
    {
        $this->writeFile($view);
        $blade = new Blade($this->getViewPath(), $this->getCachePath());

        if (is_array($data)) {
            return $blade->view()->make($view, $data)->render();
        } else {
            throw new Exception('data pass into view must be an array.');
        }
    }
1027003
protected function parseFailedJob(array $failed)
    {
        $row = array_values(Arr::except($failed, ['payload', 'exception']));

        array_splice($row, 3, 0, $this->extractJobName($failed['payload']));

        return $row;
    }
54655
protected function parseArrayOfPrimaryData(array $data)
    {
        $isValid = true;
        $result  = null;
        foreach ($data as $primaryData) {
            $parsed = $this->parseSinglePrimaryData($primaryData);
            if ($parsed === null) {
                $isValid = false;
            } else {
                $result[] = $parsed;
            }
        }

        return $isValid === true ? $result : null;
    }
300913
public function toRet(array $data = [])
    {
        if ($this->isSuccess()) {
            return $this->suc($data + (array) $this->getResponse());
        }

        $e = $this->getErrorException();
        return $this->err($data + ['code' => $e->getCode(), 'message' => $e->getMessage()]);
    }
273662
public function setData($data)
    {
        if ( ! (is_array($data) || $data instanceof Traversable)) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s expects an array or Traversable collection; invalid collection of type %s provided',
                    __METHOD__,
                    is_object($data) ? get_class($data) : gettype($data)
                )
            );
        }

        // https://github.com/zendframework/zend-inputfilter/pull/169
        $this->collectionRawValues = $data;

        foreach ($data as $item) {
            if (is_array($item) || $item instanceof Traversable) {
                continue;
            }

            throw new InvalidArgumentException(
                sprintf(
                    '%s expects each item in a collection to be an array or Traversable; '
                    . 'invalid item in collection of type %s detected',
                    __METHOD__,
                    is_object($item) ? get_class($item) : gettype($item)
                )
            );
        }

        $this->data = $data;
        return $this;
    }
315694
public static function json_decode($data)
    {
        $data_json = @json_decode($data, true);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \Exception(
                sprintf('An error occurred while trying to decode JSON data [code "%s"]!', json_last_error())
            );
        } else {
            $data = $data_json;
        }
        return $data;
    }
652650
final public function setData($data) {
        if ((is_object($data) && !is_a($data, 'Object')) || (!is_object($data) && !is_array($data)))
            throw new \Exception('Data must be either an array or an object that extends Object: ' . gettype($data));
        $data = is_array($data) ? $data : $data->toArray();
        foreach ($data as $attr => $value) {
            if ($this->elements[$attr]) {
                $this->elements[$attr]->setData($value);
            } else
                $this->data[$attr] = $value;
        }
        $this->valid = null;
        return $this;
    }