original_string: public static function processMediaActions($medium, $url)
      {
          if (!is_array($url)) {
              $url_parts = parse_url($url);
          } else {
              $url_parts = $url;
          }
  
          $actions = [];
  
          // if there is a query, then parse it and build action calls
          if (isset($url_parts['query'])) {
              $actions = array_reduce(explode('&', $url_parts['query']), function ($carry, $item) {
                  $parts = explode('=', $item, 2);
                  $value = $parts[1] ?? null;
                  $carry[] = ['method' => $parts[0], 'params' => $value];
  
                  return $carry;
              }, []);
          }
  
          if (Grav::instance()['config']->get('system.images.auto_fix_orientation')) {
              $actions[] = ['method' => 'fixOrientation', 'params' => ''];
          }
          $defaults = Grav::instance()['config']->get('system.images.defaults');
          if (is_array($defaults) && count($defaults)) {
              foreach ($defaults as $method => $params) {
                  $actions[] = [
                      'method' => $method,
                      'params' => $params,
                  ];
              }
          }
  
          // loop through actions for the image and call them
          foreach ($actions as $action) {
              $matches = [];
  
              if (preg_match('/\[(.*)\]/', $action['params'], $matches)) {
                  $args = [explode(',', $matches[1])];
              } else {
                  $args = explode(',', $action['params']);
              }
  
              $medium = call_user_func_array([$medium, $action['method']], $args);
          }
  
          if (isset($url_parts['fragment'])) {
              $medium->urlHash($url_parts['fragment']);
          }
  
          return $medium;
      }
code: public static function processMediaActions($medium, $url)
      {
          if (!is_array($url)) {
              $url_parts = parse_url($url);
          } else {
              $url_parts = $url;
          }
  
          $actions = [];
  
          // if there is a query, then parse it and build action calls
          if (isset($url_parts['query'])) {
              $actions = array_reduce(explode('&', $url_parts['query']), function ($carry, $item) {
                  $parts = explode('=', $item, 2);
                  $value = $parts[1] ?? null;
                  $carry[] = ['method' => $parts[0], 'params' => $value];
  
                  return $carry;
              }, []);
          }
  
          if (Grav::instance()['config']->get('system.images.auto_fix_orientation')) {
              $actions[] = ['method' => 'fixOrientation', 'params' => ''];
          }
          $defaults = Grav::instance()['config']->get('system.images.defaults');
          if (is_array($defaults) && count($defaults)) {
              foreach ($defaults as $method => $params) {
                  $actions[] = [
                      'method' => $method,
                      'params' => $params,
                  ];
              }
          }
  
          // loop through actions for the image and call them
          foreach ($actions as $action) {
              $matches = [];
  
              if (preg_match('/\[(.*)\]/', $action['params'], $matches)) {
                  $args = [explode(',', $matches[1])];
              } else {
                  $args = explode(',', $action['params']);
              }
  
              $medium = call_user_func_array([$medium, $action['method']], $args);
          }
  
          if (isset($url_parts['fragment'])) {
              $medium->urlHash($url_parts['fragment']);
          }
  
          return $medium;
      }
code_tokens: public static function processMediaActions ( $ medium , $ url ) { if ( ! is_array ( $ url ) ) { $ url_parts = parse_url ( $ url ) ; } else { $ url_parts = $ url ; } $ actions = [ ] ; // if there is a query, then parse it and build action calls if ( isset ( $ url_parts [ 'query' ] ) ) { $ actions = array_reduce ( explode ( '&' , $ url_parts [ 'query' ] ) , function ( $ carry , $ item ) { $ parts = explode ( '=' , $ item , 2 ) ; $ value = $ parts [ 1 ] ?? null ; $ carry [ ] = [ 'method' => $ parts [ 0 ] , 'params' => $ value ] ; return $ carry ; } , [ ] ) ; } if ( Grav :: instance ( ) [ 'config' ] -> get ( 'system.images.auto_fix_orientation' ) ) { $ actions [ ] = [ 'method' => 'fixOrientation' , 'params' => '' ] ; } $ defaults = Grav :: instance ( ) [ 'config' ] -> get ( 'system.images.defaults' ) ; if ( is_array ( $ defaults ) && count ( $ defaults ) ) { foreach ( $ defaults as $ method => $ params ) { $ actions [ ] = [ 'method' => $ method , 'params' => $ params , ] ; } } // loop through actions for the image and call them foreach ( $ actions as $ action ) { $ matches = [ ] ; if ( preg_match ( '/\[(.*)\]/' , $ action [ 'params' ] , $ matches ) ) { $ args = [ explode ( ',' , $ matches [ 1 ] ) ] ; } else { $ args = explode ( ',' , $ action [ 'params' ] ) ; } $ medium = call_user_func_array ( [ $ medium , $ action [ 'method' ] ] , $ args ) ; } if ( isset ( $ url_parts [ 'fragment' ] ) ) { $ medium -> urlHash ( $ url_parts [ 'fragment' ] ) ; } return $ medium ; }
docstring: Process media actions
  
  @param Medium $medium
  @param string|array $url
  @return Medium
docstring_tokens: Process media actions