Skip to content

Commit

Permalink
Cleanup and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrckvzn committed Oct 1, 2021
1 parent 77c6bcf commit e33bb7b
Showing 1 changed file with 67 additions and 14 deletions.
81 changes: 67 additions & 14 deletions src/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,44 @@

class Image implements Arrayable
{
/**
* @var object|Model The model the media belongs to
*/
protected $object;

/**
* @var string The media role
*/
protected $role;

/**
* @var null|Media Media object
*/
protected $media;

/**
* @var string The media crop
*/
protected $crop;

/**
* @var int The media width
*/
protected $width;

/**
* @var int The media height
*/
protected $height;

/**
* @var array The media sources
*/
protected $sources = [];

protected $layout = "fullWidth";

/**
* @var string Sizes attributes
*/
protected $sizes;

/**
Expand All @@ -50,6 +72,8 @@ public function __construct($object, $role, $media = null)
}

/**
* Pick a preset from the configuration file or pass an array with the image configuration
*
* @param array|string $preset
* @return $this
*/
Expand All @@ -66,42 +90,65 @@ public function preset($preset)
return $this;
}

/**
* Set the crop of the media to use
*
* @param string $crop
* @return $this
*/
public function crop($crop)
{
$this->crop = $crop;

return $this;
}

/**
* Set a fixed with or max-width
*
* @param int $width
* @return $this
*/
public function width($width)
{
$this->width = $width;

return $this;
}

/**
* Set a fixed height
*
* @param int $height
* @return $this
*/
public function height($height)
{
$this->height = $height;

return $this;
}

/**
* Set the image sizes attributes
*
* @param string $sizes
* @return $this
*/
public function sizes($sizes)
{
$this->sizes = $sizes;

return $this;
}

public function layout($layout)
{
$this->layout = $layout;

return $this;
}

public function sources($sources)
/**
* Set alternative sources for the media.
*
* @param array $sources
* @return $this
*/
public function sources($sources = [])
{
$this->sources = [];

Expand All @@ -123,23 +170,29 @@ public function sources($sources)
)->toArray()
];
}

return $this;
}

public function render()
/**
* Call the Facade render method to output the view
*
* @return void
*/
public function render($overrides = [])
{
return TwillImage::render($this->toArray());
return TwillImage::render($this, $overrides);
}

public function toArray()
{
$arr = [
"layout" => $this->layout,
"sizes" => $this->sizes,
"image" => $this->mediaSourceService->generate(
$this->crop,
$this->width,
$this->height
)->toArray(),
"sizes" => $this->sizes,
"sources" => $this->sources,
];

Expand Down

0 comments on commit e33bb7b

Please sign in to comment.