@param resource $res

@throws \Exception

@return array
502361
public static function loadKeyFromX509Resource($res)
    {
        $key = openssl_get_publickey($res);

        $details = openssl_pkey_get_details($key);
        if (isset($details['key'])) {
            $values = self::loadKeyFromPEM($details['key']);
            openssl_x509_export($res, $out);
            $values['x5c'] = [trim(preg_replace('#-.*-#', '', $out))];

            if (function_exists('openssl_x509_fingerprint')) {
                $values['x5t'] = Base64Url::encode(openssl_x509_fingerprint($res, 'sha1', true));
                $values['x5t#256'] = Base64Url::encode(openssl_x509_fingerprint($res, 'sha256', true));
            } else {
                openssl_x509_export($res, $pem);
                $values['x5t'] = Base64Url::encode(self::calculateX509Fingerprint($pem, 'sha1', true));
                $values['x5t#256'] = Base64Url::encode(self::calculateX509Fingerprint($pem, 'sha256', true));
            }

            return $values;
        }

        throw new \InvalidArgumentException('Unable to load the certificate');
    }
757876
public function apply($resource){
		// Extract arguments
		@list(,$x,$y,$width,$height)=func_get_args();
		$x=(int)$x;
		$y=(int)$y;
		$width=(int)$width;
		$height=(int)$height;
		// Get resolution
		$w_src=imagesx($resource);
		$h_src=imagesy($resource);
		if($w_src===false || $h_src===false){
			throw new Exception("An error was encountered while getting source image resolution");
		}
		// Verifications
		if(!$width || !$height){
			throw new Exception("Invalid image resolution provided");
		}
		if(($x+$width)>$w_src || ($y+$height)>$h_src){
			throw new Exception("Dimensions provided seems to be out of the image resolution");
		}
		// Create new image
		$image=$this->_createTrueColor($width,$height);
		// Cut image
		if(!imagecopy($image,$resource,0,0,$x,$y,$width,$height)){
			throw new Exception("Failed to copy image portion");
		}
		return $image;
	}
345921
public function getResourcesPermissions(User $user, $resources)
    {
        $permissions = [];
        if(!is_null($user)){
            try {
                $permissionManager = $this->getServiceManager()->get(PermissionInterface::SERVICE_ID);
                $supportedRights   = $permissionManager->getSupportedRights();
                $permissions['supportedRights'] = $supportedRights;

                if(count($supportedRights) > 0){
                    $uris = $this->getUris($resources);

                    $permissions['data'] = $permissionManager->getPermissions($user, $uris);
                }
            } catch(\Exception $e){
                \common_Logger::w('Unable to retrieve permssions ' . $e->getMessage());
            }
        }
        return $permissions;

    }
1230022
public function getRedirectParameters($resource = null)
    {
        $redirect = $this->parameters->get('redirect');

        if ($this->areParametersIntentionallyEmptyArray($redirect)) {
            return [];
        }

        if (!is_array($redirect)) {
            $redirect = ['parameters' => []];
        }

        $parameters = $redirect['parameters'] ?? [];
        $parameters = $this->addExtraRedirectParameters($parameters);

        if (null !== $resource) {
            $parameters = $this->parseResourceValues($parameters, $resource);
        }

        return $parameters;
    }
1176537
private function FetchFields($res)
    {
        if (!$this->debug_on) {
            return ;
        }
        $i=0;
        $this->col_info = array();
        while ($i < @pg_num_fields($res)) {
            $this->col_info[$i]->name = @pg_field_name($res, $i);
            $this->col_info[$i]->size = @pg_field_size($res, $i);
            $this->col_info[$i]->type = @pg_field_type($res, $i);
            $i++;
        }
    }
994279
public function apply($resource){
		// Get resolution
		$width=imagesx($resource);
		$height=imagesy($resource);
		if($width===false || $height===false){
			throw new Exception("An error was encountered while getting image resolution");
		}
		// Image conversion
		$new=imagecreatetruecolor($width,$height);
		if(!imagecopy($new,$resource,0,0,0,0,$width,$height)){
			throw new Exception("An error was encountered while copying image");
		}
		return $new;
	}
291195
private function parseSingleMutationResult(array $res)
    {
        $mutationResult = $res['mutationResults'][0];

        if (isset($mutationResult['conflictDetected']) && $mutationResult['conflictDetected']) {
            throw new DomainException(
                'A conflict was detected in the mutation. ' .
                'The operation failed.'
            );
        }

        // cast to string for conformance between REST and gRPC.
        return (string) $mutationResult['version'];
    }
1243372
protected function _addResources($resources)
    {
        foreach ($resources as $permission => $controllers) {
            foreach ($controllers as $controller => $actions) {
                if ($controller == 'all') {
                    $controller = null;
                } else {
                    if (!$this->hasResource($controller)) {
                        $this->addResource(new Resource($controller));
                    }
                }

                foreach ($actions as $action => $role) {
                    if ($action == 'all') {
                        $action = null;
                    }

                    if ($permission == 'allow') {
                        $this->allow($role, $controller, $action);
                    } elseif ($permission == 'deny') {
                        $this->deny($role, $controller, $action);
                    } else {
                        throw new \Exception('No valid permission defined: ' . $permission);
                    }
                }
            }
        }

        return $this;
    }
16781
public function getAll()
    {
        if (!$this->getResource()) {
            return [];
        }
        if ($this->useLocalResource) {
            return $this->localResource;
        }

        // If we're attempting to use a global resource but it doesn't exist, we've got a problem.
        if (!isset($GLOBALS[$this->getResource()])) {
            throw new \Parable\GetSet\Exception(
                "Attempting to use global resource '{$this->getResource()}' but resource not available."
            );
        }

        return $GLOBALS[$this->getResource()];
    }
377132
public function parse($resource) {
        $result = array();
        $fieldcnt = mysql_num_fields($resource);
        $fields_transform = array();
        for($i=0;$i<$fieldcnt;$i++) {
            $type = mysql_field_type($resource, $i);
            if(isset(self::$fieldTypes[$type])) {
                $fields_transform[mysql_field_name($resource, $i)] = self::$fieldTypes[$type];
            }
        }

        while($row = mysql_fetch_object($resource)) {
            foreach($fields_transform as $fieldname => $fieldtype) {
               settype($row->$fieldname, $fieldtype);
            }
            $result[] = $row;
        }
        return $result;
    }
649841
public function getStrings(\core_kernel_classes_Resource $resource)
    {
        $tokenizer = $this->getItemContentTokenizer($resource);
        if (is_null($tokenizer)) {
            return [];
        }
        return $tokenizer->getStrings($resource);
    }
24764
public function fetchSimpleList(\PDOStatement $res, $col = 0)
    {
        if (!$col) {
            $col = 0;
        }

        $result = array();
        try {
            if (!$res) {
                throw new DatabaseException(__METHOD__ . " No ressource has been given", self::NO_RESSOURCE, self::SEVERITY_LOG, __FILE__, __LINE__);
            }

            while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
                $result[] = $row[$col];
            }
        } catch (DatabaseException $e) {
            throw $e;
        }

        return $result;
    }
517891
public function getResourcePermissions(ResourceInterface $resource) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->getQuery();

        return $query->getResult();
    }
1317859
protected function getAllowedMethods(string $resource)
    {
        $cached = $this->cache['allowed_methods'][$resource] ?? null;
        if ($cached !== null) {
            return $cached;
        }

        $resource_data = $this->resources[$resource] ?? null;
        if ($resource_data === null) {
            throw new \DomainException("Invalid resource '$resource'");
        }

        $allow = $this->implemented_methods;

        $methods = (array) ($resource_data['methods'] ?? null);
        if (!empty($methods)) {
            $allow = array_intersect(
                $allow,
                array_merge($methods, ['OPTIONS'])
            );
        }

        $this->cache['allowed_methods'][$resource] = $allow;
        return $allow;
    }
1307223
private function refresh($res)
    {
        foreach ($this->data as $k => $v) {
            $this->data[$k] = isset($res[$k]) ? $res[$k] : false;
        }
        return $this->data;
    }
816065
private function serializeToArray($resource): array
    {
        $manager = new Manager();
        $manager->setSerializer(new DataArraySerializer());

        $transformation = $manager->createData($resource)->toArray();

        return $transformation['data'];
    }
1027176
public static function allPermissionsFor($resource)
    {
        $result = [];
        foreach (static::$permissions as $permission) {
            $result[] = sprintf('%s %s', $permission, str_plural($resource));
        }

        return $result;
    }