Skip to content

Commit

Permalink
Normalized style with php_cs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Mar 19, 2017
1 parent eb0a9f3 commit 910a3d6
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 214 deletions.
12 changes: 5 additions & 7 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@

class Module extends AbstractModule
{

protected $settings = array(
protected $settings = [
'iiifserver_manifest_description_property' => 'dcterms:bibliographicCitation',
'iiifserver_manifest_attribution_property' => '',
'iiifserver_manifest_attribution_default' => 'Provided by Example Organization',
Expand All @@ -57,7 +56,7 @@ class Module extends AbstractModule
'iiifserver_image_max_size' => 10000000,
'iiifserver_image_tile_dir' => 'tile',
'iiifserver_image_tile_type' => 'deepzoom',
);
];

public function getConfig()
{
Expand Down Expand Up @@ -359,7 +358,7 @@ public function deleteMediaTiles(ZendEvent $event)
* Removes directories recursively.
*
* @param string $dir Directory name.
* @return boolean
* @return bool
*/
private function rrmdir($dir)
{
Expand All @@ -376,13 +375,12 @@ private function rrmdir($dir)
return false;
}

$files = array_diff($scandir, array('.', '..'));
$files = array_diff($scandir, ['.', '..']);
foreach ($files as $file) {
$path = $dir . DIRECTORY_SEPARATOR . $file;
if (is_dir($path)) {
$this->rrmdir($path);
}
else {
} else {
unlink($path);
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'media_ingesters' => [
'factories' => [
'tile' => 'IiifServer\Service\MediaIngester\TileFactory',
]
],
],
'media_renderers' => [
'factories' => [
Expand Down
10 changes: 5 additions & 5 deletions src/AbstractImageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ abstract class AbstractImageServer implements LoggerAwareInterface, TranslatorAw
use LoggerAwareTrait, TranslatorAwareTrait;

// List of managed IIIF media types.
protected $_supportedFormats = array();
protected $_supportedFormats = [];

protected $_args;

/**
* Check if a media type is supported.
*
* @param string $mediaType
* @return boolean
* @return bool
*/
public function checkMediaType($mediaType)
{
Expand All @@ -68,7 +68,7 @@ public function checkMediaType($mediaType)
* @param array $args List of arguments for the transformation.
* @return string|null The filepath to the temp image if success.
*/
abstract public function transform(array $args = array());
abstract public function transform(array $args = []);

/**
* Prepare the extraction from the source and the requested region and size.
Expand Down Expand Up @@ -188,13 +188,13 @@ protected function _prepareExtraction()
return;
}

return array(
return [
$sourceX,
$sourceY,
$sourceWidth,
$sourceHeight,
$destinationWidth,
$destinationHeight,
);
];
}
}
34 changes: 17 additions & 17 deletions src/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace IiifServer\Controller;

use \Exception;
use Exception;
use Zend\I18n\Translator\TranslatorInterface;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
Expand Down Expand Up @@ -74,7 +74,7 @@ public function __construct(
public function indexAction()
{
$id = $this->params('id');
$this->redirect()->toRoute('iiifserver_image_info', array('id' => $id));
$this->redirect()->toRoute('iiifserver_image_info', ['id' => $id]);
}

/**
Expand Down Expand Up @@ -338,7 +338,7 @@ protected function _mediaFilePath(MediaRepresentation $media, $imageType = 'orig
*/
protected function _cleanRequest(MediaRepresentation $media)
{
$transform = array();
$transform = [];

$transform['source']['filepath'] = $this->_getImagePath($media, 'original');
$transform['source']['media_type'] = $media->mediaType();
Expand Down Expand Up @@ -492,7 +492,7 @@ protected function _cleanRequest(MediaRepresentation $media)
if ($destinationWidth && $destinationHeight) {
// Check the size only if the region is full, else it's forced.
if ($transform['region']['feature'] == 'full') {
$availableTypes = array('square', 'medium', 'large', 'original');
$availableTypes = ['square', 'medium', 'large', 'original'];
foreach ($availableTypes as $imageType) {
$filepath = $this->_getImagePath($media, $imageType);
if ($filepath) {
Expand Down Expand Up @@ -575,7 +575,7 @@ protected function _cleanRequest(MediaRepresentation $media)
}

// Simple rotation.
elseif ($rotation == 90 || $rotation == 180 || $rotation == 270) {
elseif ($rotation == 90 || $rotation == 180 || $rotation == 270) {
$transform['rotation']['feature'] = 'rotationBy90s';
$transform['rotation']['degrees'] = $rotation;
}
Expand All @@ -592,15 +592,15 @@ protected function _cleanRequest(MediaRepresentation $media)

// Determine the format.
// The regex in route checks it.
$mediaTypes = array(
$mediaTypes = [
'jpg' => 'image/jpeg',
'png' => 'image/png',
'tif' => 'image/tiff',
'gif' => 'image/gif',
'pdf' => 'application/pdf',
'jp2' => 'image/jp2',
'webp' => 'image/webp',
);
];
$transform['format']['feature'] = $mediaTypes[$format];

return $transform;
Expand Down Expand Up @@ -674,13 +674,13 @@ protected function _useOmekaDerivative(MediaRepresentation $media, $transform)
if ($useDerivativePath) {
$derivativePath = $this->_getImagePath($media, $derivativeType);

return array(
return [
'filepath' => $derivativePath,
'derivativeType' => $derivativeType,
'media_type' => 'image/jpeg',
'width' => $derivativeWidth,
'height' => $derivativeHeight,
);
];
}
}

Expand Down Expand Up @@ -735,10 +735,10 @@ protected function _getImageSize(MediaRepresentation $media, $imageType = 'origi
{
// Check if this is an image.
if (empty($media) || strpos($media->mediaType(), 'image/') !== 0) {
return array(
return [
'width' => null,
'height' => null,
);
];
}

// The storage adapter should be checked for external storage.
Expand Down Expand Up @@ -804,25 +804,25 @@ protected function _getWidthAndHeight($filepath)
if ($result !== false) {
list($width, $height) = getimagesize($tempPath);
unlink($tempPath);
return array(
return [
'width' => $width,
'height' => $height,
);
];
}
unlink($tempPath);
}
// A normal path.
elseif (file_exists($filepath)) {
list($width, $height) = getimagesize($filepath);
return array(
return [
'width' => $width,
'height' => $height,
);
];
}

return array(
return [
'width' => null,
'height' => null,
);
];
}
}
2 changes: 1 addition & 1 deletion src/Controller/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(FileManager $fileManager, ModuleManager $moduleManag
public function indexAction()
{
$id = $this->params('id');
$this->redirect()->toRoute('iiifserver_media_info', array('id' => $id));
$this->redirect()->toRoute('iiifserver_media_info', ['id' => $id]);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/PresentationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

class PresentationController extends AbstractActionController
{

/**
* Forward to the 'manifest' action.
*
Expand All @@ -56,7 +55,7 @@ public function manifestAction()
}

// Map iiif resources with Omeka Classic and Omeka S records.
$matchingResources = array(
$matchingResources = [
'item' => 'items',
'items' => 'items',
'item-set' => 'item_sets',
Expand All @@ -65,7 +64,7 @@ public function manifestAction()
'item_sets' => 'item_sets',
'collection' => 'item_sets',
'collections' => 'item_sets',
);
];
$resourceName = $this->params('resourcename');
if (!isset($matchingResources[$resourceName])) {
throw new NotFoundException;
Expand Down
3 changes: 1 addition & 2 deletions src/Form/ConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class ConfigForm extends Form
{

protected $api;
protected $settings;

Expand Down Expand Up @@ -116,7 +115,7 @@ public function init()
'type' => 'Checkbox',
'options' => [
'label' => 'Force https', // @translate
'info' => 'In some cases, the json files (manifest and info) on a secured site (https) contains some urls with the scheme "http".' // @translate
'info' => 'In some cases, the json files (manifest and info) on a secured site (https) contains some urls with the scheme "http".' // @translate
. ' ' . 'This option forces all Omeka absolute urls in these files to start with the scheme "https".' // @translate
. ' ' . 'Of course, this should be unchecked on a http-only site.', // @translate
],
Expand Down
4 changes: 2 additions & 2 deletions src/ImageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ImageServer implements LoggerAwareInterface, TranslatorAwareInterface
use LoggerAwareTrait, TranslatorAwareTrait;

protected $_creator;
protected $_args = array();
protected $_args = [];
protected $fileManager;
protected $commandLineArgs;

Expand Down Expand Up @@ -90,7 +90,7 @@ public function setArgs($args)
* @param array $args List of arguments for the transformation.
* @return string|null The filepath to the temp image if success.
*/
public function transform(array $args = array())
public function transform(array $args = [])
{
if (!empty($args)) {
$this->setArgs($args);
Expand Down
14 changes: 7 additions & 7 deletions src/ImageServer/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
*/
class Auto extends AbstractImageServer
{
protected $_gdMediaTypes = array();
protected $_imagickMediaTypes = array();
protected $_gdMediaTypes = [];
protected $_imagickMediaTypes = [];

protected $fileManager;
protected $commandLineArgs;
Expand All @@ -57,15 +57,15 @@ public function __construct(FileManager $fileManager, array $commandLineArgs)

// If available, use GD when source and destination formats are managed.
if (extension_loaded('gd')) {
$this->_gdMediaTypes = array(
$this->_gdMediaTypes = [
'image/jpeg' => true,
'image/png' => true,
'image/tiff' => false,
'image/gif' => true,
'application/pdf' => false,
'image/jp2' => false,
'image/webp' => true,
);
];
$gdInfo = gd_info();
if (empty($gdInfo['GIF Read Support']) || empty($gdInfo['GIF Create Support'])) {
$this->_gdMediaTypes['image/gif'] = false;
Expand All @@ -76,15 +76,15 @@ public function __construct(FileManager $fileManager, array $commandLineArgs)
}

if (extension_loaded('imagick')) {
$iiifMediaTypes = array(
$iiifMediaTypes = [
'image/jpeg' => 'JPG',
'image/png' => 'PNG',
'image/tiff' => 'TIFF',
'image/gif' => 'GIF',
'application/pdf' => 'PDF',
'image/jp2' => 'JP2',
'image/webp' => 'WEBP',
);
];
$this->_imagickMediaTypes = array_intersect($iiifMediaTypes, \Imagick::queryFormats());
}

Expand All @@ -100,7 +100,7 @@ public function __construct(FileManager $fileManager, array $commandLineArgs)
* @param array $args List of arguments for the transformation.
* @return string|null The filepath to the temp image if success.
*/
public function transform(array $args = array())
public function transform(array $args = [])
{
// GD seems to be 15% speeder, so it is used first if available.
if (!empty($this->_gdMediaTypes[$args['source']['media_type']])
Expand Down
13 changes: 7 additions & 6 deletions src/ImageServer/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
class GD extends AbstractImageServer
{
// List of managed IIIF media types.
protected $_supportedFormats = array(
protected $_supportedFormats = [
'image/jpeg' => true,
'image/png' => true,
'image/tiff' => false,
'image/gif' => true,
'application/pdf' => false,
'image/jp2' => false,
'image/webp' => true,
);
];

protected $fileManager;

Expand Down Expand Up @@ -84,7 +84,7 @@ public function __construct(FileManager $fileManager)
* @param array $args List of arguments for the transformation.
* @return string|null The filepath to the temp image if success.
*/
public function transform(array $args = array())
public function transform(array $args = [])
{
if (empty($args)) {
return;
Expand Down Expand Up @@ -208,9 +208,9 @@ public function transform(array $args = array())
// GD uses counterclockwise rotation.
$degrees = abs(360 - $args['rotation']['degrees']);
// Keep the transparency if possible.
$transparency = imagecolorallocatealpha($destinationGD , 0, 0, 0, 127);
$transparency = imagecolorallocatealpha($destinationGD, 0, 0, 0, 127);
imagefill($destinationGD, 0, 0, $transparency);
$destinationGDrotated = imagerotate( $destinationGD, $degrees, $transparency);
$destinationGDrotated = imagerotate($destinationGD, $degrees, $transparency);
imagedestroy($destinationGD);
if ($destinationGDrotated === false) {
imagedestroy($sourceGD);
Expand Down Expand Up @@ -324,7 +324,8 @@ protected function _loadImageResource($source)
}
} catch (Exception $e) {
$logger = $this->getLogger();
$t = $this->getTranslator();;
$t = $this->getTranslator();
;
$logger->log(Logger::ERR, sprintf($t->translate("GD failed to open the file \"%s\". Details:\n%s"), $source, $e->getMessage()));
return false;
}
Expand Down
Loading

0 comments on commit 910a3d6

Please sign in to comment.