src/acdhOeaw/fedora/dissemination/Parameter.php
static public function value(FedoraResource $res, string $valueProp,
                                 string $default, array $transformations): string {
        $value = $default;

        if ($valueProp !== '') {
            $matches = $res->getMetadata()->all($valueProp);
            if (count($matches) > 0) {
                $value = (string) $matches[0];
            }
        }

        foreach ($transformations as $i) {
            $matches = [];
            preg_match('|^([^(]+)([(].*[)])?$|', $i, $matches);
            $name    = $matches[1];
            if (!isset(self::$transformations[$name])) {
                throw new RuntimeException('unknown transformation');
            }

            $param = [$value];
            if (isset($matches[2])) {
                $tmp = explode(',', substr($matches[2], 1, -1));
                foreach ($tmp as $j) {
                    $param[] = trim($j);
                }
            }

            $transformation = new self::$transformations[$name]();
            $value          = $transformation->transform(...$param);
        }

        return $value;
    }
static public function value(FedoraResource $res, string $valueProp,
                                 string $default, array $transformations): string {
        $value = $default;

        if ($valueProp !== '') {
            $matches = $res->getMetadata()->all($valueProp);
            if (count($matches) > 0) {
                $value = (string) $matches[0];
            }
        }

        foreach ($transformations as $i) {
            $matches = [];
            preg_match('|^([^(]+)([(].*[)])?$|', $i, $matches);
            $name    = $matches[1];
            if (!isset(self::$transformations[$name])) {
                throw new RuntimeException('unknown transformation');
            }

            $param = [$value];
            if (isset($matches[2])) {
                $tmp = explode(',', substr($matches[2], 1, -1));
                foreach ($tmp as $j) {
                    $param[] = trim($j);
                }
            }

            $transformation = new self::$transformations[$name]();
            $value          = $transformation->transform(...$param);
        }

        return $value;
    }
static public function value ( FedoraResource $ res , string $ valueProp , string $ default , array $ transformations ) : string { $ value = $ default ; if ( $ valueProp !== '' ) { $ matches = $ res -> getMetadata ( ) -> all ( $ valueProp ) ; if ( count ( $ matches ) > 0 ) { $ value = ( string ) $ matches [ 0 ] ; } } foreach ( $ transformations as $ i ) { $ matches = [ ] ; preg_match ( '|^([^(]+)([(].*[)])?$|' , $ i , $ matches ) ; $ name = $ matches [ 1 ] ; if ( ! isset ( self :: $ transformations [ $ name ] ) ) { throw new RuntimeException ( 'unknown transformation' ) ; } $ param = [ $ value ] ; if ( isset ( $ matches [ 2 ] ) ) { $ tmp = explode ( ',' , substr ( $ matches [ 2 ] , 1 , - 1 ) ) ; foreach ( $ tmp as $ j ) { $ param [ ] = trim ( $ j ) ; } } $ transformation = new self :: $ transformations [ $ name ] ( ) ; $ value = $ transformation -> transform ( ... $ param ) ; } return $ value ; }
Returns parameter value for a given resource.
@param FedoraResource $res repository resource to return the value for
@param string $valueProp RDF property holding the parameter value. If
empty, the $default value is used.
@param string $default parameter default value
@param string $transformations transformations to be applied to the parameter value
@return string
Returns parameter value for a given resource .