Skip to content
This repository was archived by the owner on Mar 1, 2018. It is now read-only.
This repository was archived by the owner on Mar 1, 2018. It is now read-only.

Mismatch in README and doctrine image functionality #4

@danielholmes

Description

@danielholmes

The example given in the readme:

sf_image:
  class: sfImageTransformRoute
  url:   /thumbnails/:type/:format/:path/:slug-:id.:sf_format
  param: { module: sfImageTransformator, action: index, attribute: file }
  ...
  options:
    image_source: Doctrine

Within the sfImageSourceDoctrine, the path parameter seems to be ignored. If you look at the translated filepath, it seems the filepath is extracted from the class name instead:

sfConfig::get('sf_upload_dir').'/'.strtolower(get_class($obj)).'/'.$obj->$attribute

So it will work by accident if you use the path /uploads/modelname. The Propel source has a different implementation but still broken; the buildURIfromParameters seems to ignore the path in both.

Apologies for the crude format of this fix, but i found this to work for me (in sfImageSourceDoctrine). It also works in the case the developer just uses the root /uploads directory:

public static function buildURIfromParameters(array $parameters)
{
  ...

  $path = $parameters['attribute'];
  if (isset($parameters['path']))
  {
    $path = $parameters['path'] . '/' . $path;
  }
  return sprintf('sfImageSource://%s/%s#%s', $parameters['type'], $path, $parameters['id']);
}

protected function translatePathToFilename($path)
{
  ...
  $filepath = sfConfig::get('sf_upload_dir');
  $path = ltrim($url['path'], '/');
  $slashPos = strrpos($path, '/');
  $attribute = null;
  if ($slashPos === false)
  {
    $attribute = $path;
  }
  else
  {
    $attribute = substr($path, $slashPos + 1);
    $filepath .= '/' . substr($path, 0, $slashPos);
  }
  $filepath .= '/' . $obj->$attribute;
  return $filepath;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions