If is defined return a Api Resource object

@param string $type
@param collection $data
@return Resource | Model
775939
protected function maybeMakeResource($type, $data, $status = 200) {
        $resourceName = $type . 'Resource';
        if(isset($this->$resourceName) && $this->$resourceName) {
            $class = $this->$resourceName;
            return (new $class($data))->response()
            ->setStatusCode($status);
        } elseif(is_bool($data)){
            return strval($data);
        } else {
            return $data;
        }
    }
424651
public function factoryFromArray(array $data, $type = null)
    {
        if ($type === null) {
            if (array_key_exists('type', $data)) {
                $type = $data['type'];
                unset($data['type']);
            } else {
                throw new \InvalidArgumentException(
                    'Parameter type not specified in PaymentDataFactory.factoryFromArray()'
                );
            }
        }

        $paymentData = $this->factory($type);
        $this->fillModel($paymentData, $data);

        return $paymentData;
    }
230531
public function call($method, array $data = null, $type = 'get')
    {
        $url = self::URL_PREFIX . '/' . $method . '?auth_token=' . $this->token;
        if ($data && $type == 'get') {
            $url .= '&' . implode('&', $data);
        }

        $options = [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true
        ];
        if ($data && $type == 'post') {
            $options[CURLOPT_POST] = true;
            $options[CURLOPT_POSTFIELDS] = $data;
        }
        $response = self::jsonValidate($this->executeCurl($options), $this->returnArray);

        return $response['data'];
    }
683563
protected function processResourceData(array $resourceData, array $parentModels, $type)
    {
        try {
            $this->seenTypes[$type] = $resourceData;
            return parent::processResourceData($resourceData, $parentModels, $type);
        } catch (MissingResolverException $exception) {
        } catch (\ReflectionException $exception) {
        }

        return null;
    }
1186752
public function joinTablesOnCollectionByType($collection, $type)
    {
        if ($type == \Dotdigitalgroup\Email\Model\Rules::ABANDONED) {
            $collection->getSelect()
                ->joinLeft(
                    ['quote_address' => $this->getTable('quote_address')],
                    'main_table.entity_id = quote_address.quote_id',
                    ['shipping_method', 'country_id', 'city', 'region_id']
                )->joinLeft(
                    ['quote_payment' => $this->getTable('quote_payment')],
                    'main_table.entity_id = quote_payment.quote_id',
                    ['method']
                )->where('address_type = ?', 'shipping');
        } elseif ($type == \Dotdigitalgroup\Email\Model\Rules::REVIEW) {
            $collection->getSelect()
                ->join(
                    ['order_address' => $this->getTable('sales_order_address')],
                    'main_table.entity_id = order_address.parent_id',
                    ['country_id', 'city', 'region_id']
                )->join(
                    ['order_payment' => $this->getTable('sales_order_payment')],
                    'main_table.entity_id = order_payment.parent_id',
                    ['method']
                )->where('order_address.address_type = ?', 'shipping');
        }

        return $collection;
    }
355234
public function supportsDenormalization($data, $type, $format = null)
    {
        if ($type !== static::TYPE) {
            return false;
        }

        if (!is_null($data) and !is_scalar($data) and !is_resource($data) and !is_array($data)) {
            return false;
        }

        return true;
    }
306289
public function load($resource, $type = null)
    {
        $collection = $this->loader->load($resource, $type);

        foreach ($collection->all() as $route) {
            if ('https' === $route->getRequirement('_scheme')) {
                $requirements = $route->getRequirements();
                unset($requirements['_scheme']);
                $route->setRequirements($requirements);
            }
        }

        return $collection;
    }
1060374
public function get($type = 'sent', $fields = ['*'])
    {
        // filter anything that is not an available type
        $type = in_array($type, ['sent', 'draft', 'outbox']) ? $type : 'sent';

        $params = $this->prepareParams();

        if ( ! empty($fields) && is_array($fields) && $fields != ['*']) {
            $params['fields'] = $fields;
        }

        $response = $this->restClient->get($this->endpoint . '/' . $type, $params);

        $entities = $this->generateCollection($response['body']);

        return $entities;
    }
79449
public function haveInCollection($collection, array $data)
    {
        $collection = $this->driver->getDbh()->selectCollection($collection);
        if ($this->driver->isLegacy()) {
            $collection->insert($data);
            return $data['_id'];
        }

        $response = $collection->insertOne($data);
        return (string) $response->getInsertedId();
    }
710384
public function addType($name, $type, $data = null, $options = array())
    {
        $this->types[$name] = $type;
        $this->data[$name] = $data;
        $this->options[$name] = $options;

        return $this;
    }
145653
public function loadObject($data)
    {
        if (!\is_object($data)) {
            throw new \InvalidArgumentException('param type error! must is object.');
        }

        return $this->bindData($this->data, $data);
    }
73726
public static function secureKnownType($data, string $type)
    {
        $filterType = 'text';

        if ($type === 'int' || $type === 'integer') {
            $filterType = FILTER_VALIDATE_INT;
        } elseif ($type === 'float' || $type === 'double') {
            $filterType = FILTER_VALIDATE_FLOAT;
        } elseif ($type === 'bool' || $type === 'boolean') {
            $filterType = FILTER_VALIDATE_BOOLEAN;
        } elseif ($type === 'email') {
            $filterType = FILTER_VALIDATE_EMAIL;
        }

        if ($filterType === 'text') {
            throw new Exception(
                'Cannot secure the type',
                self::ERR_SECURE_KNOWN_TYPE_FILTER_NOT_MANAGED
            );
        }

        return filter_var($data, $filterType);
    }
1225855
public function load($resource, $type = null)
    {
        $collection = new SymfonyRouteCollection();
        try{
            $results = $this->manager->findAllAlias();
        }catch (\Exception $e){
            return $collection;
        }
        foreach ($results as $metatag) {
            if (is_array($metatag['pathinfo'])) {
                $pathinfo = $metatag['pathinfo'];
            } else {
                $pathinfo = @unserialize($metatag['pathinfo']);
            }
            if (!is_array($pathinfo) || !isset($pathinfo['_route']) || !isset($metatag['alias'])) {
                continue;
            }
            $oldroute = $pathinfo['_route'];

            //add defaults to routealias
            if (isset($pathinfo['__defaults']) && is_array($pathinfo['__defaults'])) {
                foreach ($pathinfo['__defaults'] as $key => $value) {
                    if (strpos($key, '_') !== 0) {
                        $metatag['alias'] .= '-{'.$key.'}';
                    }
                }
            }
            $route = new Route($metatag['alias'], $pathinfo, array(), array());
            $collection->add(self::getRouteName($oldroute, $pathinfo), $route);
        }

        return $collection;
    }
566476
public function parseType(Object\TypeObjectInterface $type, $data)
    {
        if($type instanceof Object\ReferentialInterface && $type->hasRef()) {
            $objectType = $type->getRef();
            $type = $this->resolveReference($type);
        } else {
            try {
                $objectType = $type->getType();
            } catch(SwaggerException\MissingDocumentPropertyException $e) {
                $objectType = null;
            }
        }
        
        if($objectType == 'array') {
            $schemaObject = [];
            
            $arrayItemType = $type->getItems();
            
            foreach($data as $key => $value) {
                $schemaObject[$key] = $this->parseType($arrayItemType, $value);
            }
        } elseif($type instanceof Object\Schema) {
            $schemaObject = new SchemaObject($objectType);
        
            foreach(array_keys(get_object_vars($data)) as $propertyKey) {
                try {
                    $propertySchema = $this->findSchemaForProperty($type, $propertyKey);
                } catch(SwaggerException\MissingDocumentPropertyException $e) {
                    throw (new SwaggerException\UndefinedPropertySchemaException)
                        ->setPropertyName($name)
                        ->setSchema($type);
                }
            
                $propertyValue = $this->parseType(
                    $propertySchema,
                    $data->$propertyKey
                );
                
                $schemaObject->setProperty($propertyKey, $propertyValue);
            }
        } else {
            $schemaObject = $data;
        }
        
        return $schemaObject;
    }
978457
protected function setDataToCollection(Collection $collection, $data)
    {
        // set parent
        if (!empty($data['parent'])) {
            $collectionEntity = $this->collectionRepository->findCollectionById($data['parent']);
            $collection->setParent($this->getApiEntity($collectionEntity, $data['locale']));
        }

        // set other data
        foreach ($data as $attribute => $value) {
            if ($value) {
                switch ($attribute) {
                    case 'title':
                        $collection->setTitle($value);
                        break;
                    case 'key':
                        $collection->setKey($value);
                        break;
                    case 'description':
                        $collection->setDescription($value);
                        break;
                    case 'style':
                        $collection->setStyle($value);
                        break;
                    case 'type':
                        if (!isset($value['id'])) {
                            break;
                        }
                        $type = $this->getTypeById($value['id']);
                        $collection->setType($type);
                        break;
                    case 'changer':
                        $collection->setChanger($value);
                        break;
                    case 'creator':
                        $collection->setCreator($value);
                        break;
                    case 'properties':
                        $collection->setProperties($value);
                        break;
                }
            }
        }

        return $collection;
    }
4023
public function createForm($type, $data = null, array $options = [])
    {
        return $this->application['form.factory']->create($type, $data, $options);
    }
190447
public static function type($data = false) {

        if ($data) {

            $dataType = gettype($data);

            if ($dataType === 'string') {

                if (Validate::isJson($data)) {
                    $dataType = 'json';
                }
            }

            return $dataType;
        }

        return false;
    }