Verified Commit d44fa496 authored by Ingo Pfennigstorf's avatar Ingo Pfennigstorf
Browse files

Migrate to psr-2

parent a710322f
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This file represents the configuration for Code Sniffing PSR-2-related
* automatic checks of coding guidelines
* Install @fabpot's great php-cs-fixer tool via
*
* $ composer global require friendsofphp/php-cs-fixer
*
* And then simply run
*
* $ php-cs-fixer fix --config-file Build/.php_cs
*
* inside the TYPO3 directory. Warning: This may take up to 10 minutes.
*
* For more information read:
* http://www.php-fig.org/psr/psr-2/
* http://cs.sensiolabs.org
*/
if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
// Define in which folders to search and which folders to exclude
// Exclude some directories that are excluded by Git anyways to speed up the sniffing
$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('vendor')
->exclude('typo3conf')
->exclude('typo3temp')
->in(__DIR__ . '/../');
// Return a Code Sniffing configuration using
// all sniffers needed for PSR-2
// and additionally:
// - Remove leading slashes in use clauses.
// - PHP single-line arrays should not have trailing comma.
// - Single-line whitespace before closing semicolon are prohibited.
// - Remove unused use statements in the PHP source code
// - Ensure Concatenation to have at least one whitespace around
// - Remove trailing whitespace at the end of blank lines.
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
// If changes to the fixers are done, please sync them with typo3/sysext/core/Build/Scripts/cglFixMyCommit.sh
'remove_leading_slash_use',
'single_array_no_trailing_comma',
'spaces_before_semicolon',
'unused_use',
'concat_with_spaces',
'whitespacy_lines',
'ordered_use',
'single_quote',
'duplicate_semicolon',
'extra_empty_lines',
'phpdoc_no_package',
'phpdoc_scalar',
'no_empty_lines_after_phpdocs',
'short_array_syntax',
'array_element_white_space_after_comma',
'function_typehint_space',
'hash_to_slash_comment',
'join_function',
'lowercase_cast',
'namespace_no_leading_whitespace',
'native_function_casing',
'no_empty_statement',
'self_accessor',
'short_bool_cast',
'unneeded_control_parentheses'
])
->finder($finder);
This diff is collapsed.
......@@ -4,8 +4,7 @@ namespace Subugoe\Pazpar2\Controller;
/*******************************************************************************
* Copyright notice
*
* Copyright (C) 2010-2011 by Sven-S. Porst, SUB Göttingen
* <porst@sub.uni-goettingen.de>
* Copyright (C) 2013 by SUB Göttingen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -27,12 +26,8 @@ namespace Subugoe\Pazpar2\Controller;
******************************************************************************/
/**
* Pazpar2neuerwerbungenController.php
*
* Main controller for pazpar2 Neuerwerbungen plug-in,
* of the pazpar2 Extension.
*
* @author Sven-S. Porst <porst@sub-uni-goettingen.de>
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder;
......@@ -40,80 +35,80 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder;
/**
* Controller for the pazpar2 Neuerwerbungen package.
*/
class Pazpar2neuerwerbungenController extends Pazpar2Controller {
/**
* Model object used for handling the parameters.
* @var \Subugoe\Pazpar2\Domain\Model\Pazpar2neuerwerbungen
*/
protected $pz2Neuerwerbungen;
/**
* Initialiser.
*
* Initialises parent class and sets up model object.
*
* @return void
*/
public function initializeAction() {
parent::initializeAction();
$this->pz2Neuerwerbungen = GeneralUtility::makeInstance(\Subugoe\Pazpar2\Domain\Model\Pazpar2neuerwerbungen::class);
$this->pz2Neuerwerbungen->setRootPPN($this->conf['neuerwerbungen-subjects']);
$this->pz2Neuerwerbungen->setRequestArguments($this->request->getArguments());
$this->pz2Neuerwerbungen->setMonthCount($this->conf['numberOfMonths']);
}
/**
* Index: Make superclass insert <script> and <link> tags into <head>.
* Load subjects, set up the query string, run the superclass’ action
* (which does the relevant pazpar2 queries if necessary) and assign the
* results to the view.
*
* @return void
*/
public function indexAction() {
$queryString = $this->pz2Neuerwerbungen->searchQueryWithEqualsAndWildcard();
$this->query->setQueryString($queryString);
parent::indexAction();
$this->view->assign('pazpar2neuerwerbungen', $this->pz2Neuerwerbungen);
}
/**
* Inserts headers into page: first general ones by the superclass,
* then our own.
*
* @return void
*/
protected function addResourcesToHead() {
parent::addResourcesToHead();
// Add pz2-neuerwerbungen.css to <head>.
$cssTag = new TagBuilder('link');
$cssTag->addAttribute('rel', 'stylesheet');
$cssTag->addAttribute('type', 'text/css');
$cssTag->addAttribute('href', $this->conf['pz2-neuerwerbungenCSSPath']);
$cssTag->addAttribute('media', 'all');
$this->response->addAdditionalHeaderData($cssTag->render());
// Add pz2-neuerwerbungen.js to <head>.
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->addAttribute('src', $this->conf['pz2-neuerwerbungenJSPath']);
$scriptTag->forceClosingTag(true);
$this->response->addAdditionalHeaderData($scriptTag->render());
// Make jQuery initialise pazpar2neuerwerbungen when the DOM is ready.
$jsCommand = 'jQuery(document).ready(pz2neuerwerbungenDOMReady);';
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->setContent($jsCommand);
$this->response->addAdditionalHeaderData($scriptTag->render());
}
class Pazpar2neuerwerbungenController extends Pazpar2Controller
{
/**
* Model object used for handling the parameters.
* @var \Subugoe\Pazpar2\Domain\Model\Pazpar2neuerwerbungen
*/
protected $pz2Neuerwerbungen;
/**
* Initializer.
*
* Initializes parent class and sets up model object.
*
* @return void
*/
public function initializeAction()
{
parent::initializeAction();
$this->pz2Neuerwerbungen = GeneralUtility::makeInstance(\Subugoe\Pazpar2\Domain\Model\Pazpar2neuerwerbungen::class);
$this->pz2Neuerwerbungen->setRootPPN($this->conf['neuerwerbungen-subjects']);
$this->pz2Neuerwerbungen->setRequestArguments($this->request->getArguments());
$this->pz2Neuerwerbungen->setMonthCount($this->conf['numberOfMonths']);
}
/**
* Index: Make superclass insert <script> and <link> tags into <head>.
* Load subjects, set up the query string, run the superclass’ action
* (which does the relevant pazpar2 queries if necessary) and assign the
* results to the view.
*
* @return void
*/
public function indexAction()
{
$queryString = $this->pz2Neuerwerbungen->searchQueryWithEqualsAndWildcard();
$this->query->setQueryString($queryString);
parent::indexAction();
$this->view->assign('pazpar2neuerwerbungen', $this->pz2Neuerwerbungen);
}
/**
* Inserts headers into page: first general ones by the superclass,
* then our own.
*
* @return void
*/
protected function addResourcesToHead()
{
parent::addResourcesToHead();
// Add pz2-neuerwerbungen.css to <head>.
$cssTag = new TagBuilder('link');
$cssTag->addAttribute('rel', 'stylesheet');
$cssTag->addAttribute('type', 'text/css');
$cssTag->addAttribute('href', $this->conf['pz2-neuerwerbungenCSSPath']);
$cssTag->addAttribute('media', 'all');
$this->response->addAdditionalHeaderData($cssTag->render());
// Add pz2-neuerwerbungen.js to <head>.
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->addAttribute('src', $this->conf['pz2-neuerwerbungenJSPath']);
$scriptTag->forceClosingTag(true);
$this->response->addAdditionalHeaderData($scriptTag->render());
// Make jQuery initialise pazpar2neuerwerbungen when the DOM is ready.
$jsCommand = 'jQuery(document).ready(pz2neuerwerbungenDOMReady);';
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->setContent($jsCommand);
$this->response->addAdditionalHeaderData($scriptTag->render());
}
}
......@@ -4,7 +4,7 @@ namespace Subugoe\Pazpar2\Controller;
/*******************************************************************************
* Copyright notice
*
* Copyright (C) 2013 by Sven-S. Porst <ssp-web@earthlingsoft.net>
* Copyright (C) 2013 by SUB Göttingen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -30,8 +30,6 @@ namespace Subugoe\Pazpar2\Controller;
*
* Main controller for pazpar2 Service Proxy plug-in,
* of the pazpar2 Extension.
*
* @author Sven-S. Porst <ssp-web@earthlingsoft.net>
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder;
......@@ -39,59 +37,60 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder;
/**
* Controller for the pazpar2 Service Proxy package.
*/
class Pazpar2serviceproxyController extends Pazpar2Controller {
/**
* Returns the path of the pazpar2 service on the server or NULL.
*
* @return String|NULL
*/
protected function getPazpar2Path() {
return $this->conf['serviceProxyPath'];
}
/**
* @return \Subugoe\Pazpar2\Domain\Model\Query
*/
protected function createQuery() {
$query = GeneralUtility::makeInstance(\Subugoe\Pazpar2\Domain\Model\QueryServiceProxy::class);
$query->setServiceProxyAuthPath($this->conf['serviceProxyAuthPath']);
$query->setPazpar2Path($this->getPazpar2Path());
return $query;
}
class Pazpar2serviceproxyController extends Pazpar2Controller
{
/**
* Returns the path of the pazpar2 service on the server or NULL.
*
* @return String|NULL
*/
protected function getPazpar2Path()
{
return $this->conf['serviceProxyPath'];
}
/**
* Adds <script> element to <head> containing the configuration for the
* pazpar2 Service to use.
*
* @return void
*/
protected function addServiceConfigurationToHead() {
// Add pz2urlrecipe.js to <head> if URL recipes are to be used.
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->addAttribute('src', $this->conf['pz2urlrecipeJSPath']);
$scriptTag->forceClosingTag(true);
$this->response->addAdditionalHeaderData($scriptTag->render());
/**
* @return \Subugoe\Pazpar2\Domain\Model\Query
*/
protected function createQuery()
{
$query = GeneralUtility::makeInstance(\Subugoe\Pazpar2\Domain\Model\QueryServiceProxy::class);
$query->setServiceProxyAuthPath($this->conf['serviceProxyAuthPath']);
$query->setPazpar2Path($this->getPazpar2Path());
return $query;
}
// Add Service Proxy configuration to <head> before pz2.js is included.
$jsVariables = array(
'useServiceProxy' => 'true',
'serviceProxyAuthPath' => json_encode($this->conf['serviceProxyAuthPath']),
'pazpar2Path' => json_encode($this->conf['serviceProxyPath'])
);
/**
* Adds <script> element to <head> containing the configuration for the
* pazpar2 Service to use.
*
* @return void
*/
protected function addServiceConfigurationToHead()
{
// Add pz2urlrecipe.js to <head> if URL recipes are to be used.
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->addAttribute('src', $this->conf['pz2urlrecipeJSPath']);
$scriptTag->forceClosingTag(true);
$this->response->addAdditionalHeaderData($scriptTag->render());
$jsCommand = "\n";
foreach ($jsVariables as $name => $value) {
$jsCommand .= $name . ' = ' . $value . ";\n";
}
// Add Service Proxy configuration to <head> before pz2.js is included.
$jsVariables = [
'useServiceProxy' => 'true',
'serviceProxyAuthPath' => json_encode($this->conf['serviceProxyAuthPath']),
'pazpar2Path' => json_encode($this->conf['serviceProxyPath'])
];
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->setContent($jsCommand);
$this->response->addAdditionalHeaderData($scriptTag->render());
}
$jsCommand = "\n";
foreach ($jsVariables as $name => $value) {
$jsCommand .= $name . ' = ' . $value . ";\n";
}
$scriptTag = new TagBuilder('script');
$scriptTag->addAttribute('type', 'text/javascript');
$scriptTag->setContent($jsCommand);
$this->response->addAdditionalHeaderData($scriptTag->render());
}
}
This diff is collapsed.
<?php
namespace Subugoe\Pazpar2\Domain\Model;
/*******************************************************************************
* Copyright notice
*
* Copyright (C) 2013 by Sven-S. Porst, SUB Göttingen
* <porst@sub.uni-goettingen.de>
* Copyright (C) 2013 by SUB Göttingen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
......@@ -25,123 +25,109 @@ namespace Subugoe\Pazpar2\Domain\Model;
* THE SOFTWARE.
******************************************************************************/
/**
* QueryPazpar2.php
*
* Pazpar2 specific aspects of the Query class.
*
* @author Sven-S. Porst <porst@sub-uni-goettingen.de>
*/
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Query model object.
*/
class QueryPazpar2 extends Query {
/**
* VARIABLES FOR INTERNAL USE
*/
/**
* Stores session ID while pazpar2 is running.
* @var string
*/
protected $pazpar2SessionID;
/**
* Returns URL for pazpar2 search command.
*
* @return string
*/
protected function pazpar2SearchURL () {
return $this->appendSessionID(parent::pazpar2SearchURL());
}
/**
* Returns URL for a status request of the current pazpar2 session.
*
* @return string
*/
protected function pazpar2StatURL () {
return $this->appendSessionID(parent::pazpar2StatURL());
}
/**
* Returns URL for downloading pazpar2 results.
* The parameters can be used to give the the start record
* as well as the number of records required.
*
* TYPO3 typically starts running into out of memory errors when fetching
* around 1000 records in one go with a 128MB memory limit for PHP.
*
* @param int $start index of first record to retrieve (optional, default: 0)
* @param int $num number of records to retrieve (optional, default: 500)
* @return string
*/
protected function pazpar2ShowURL ($start=0, $num=500) {
return $this->appendSessionID(parent::pazpar2ShowURL($start, $num));
}
/**
* Appends the session ID to $URL.
*
* @param string $URL
* @return string
*/
protected function appendSessionID ($URL) {
return $URL . '&session=' . $this->pazpar2SessionID;
}
/**
* Initialise the pazpar2 session and store the session ID in $pazpar2SessionID.
*
* @return boolean TRUE when initialisation was successful
*/
protected function initialiseSession () {
$this->queryStartTime = time();
$initReplyString = $this->fetchURL($this->pazpar2InitURL());
$initReply = GeneralUtility::xml2array($initReplyString);
if ($initReply) {
$status = $initReply['status'];
if ($status === 'OK') {
$sessionID = $initReply['session'];
if ($sessionID) {
$this->pazpar2SessionID = $sessionID;
}
else {
GeneralUtility::devLog('did not receive pazpar2 session ID', 'pazpar2', 3);
}
// Extract access rights information if it is available.
if (array_key_exists('accessRights', $initReply)) {
$accessRights = $initReply['accessRights'];
$this->setInstitutionName($accessRights['institutionName']);
$this->setAllTargetsActive($accessRights['allTargetsActive'] === '1');
}
}
else {
GeneralUtility::devLog('pazpar2 init status is not "OK" but "' . $status . '"', 'pazpar2', 3);
}
}
else {
GeneralUtility::devLog('could not parse pazpar2 init reply', 'pazpar2', 3);
}
return ($this->pazpar2SessionID !== NULL);
}
class QueryPazpar2 extends Query
{
/**
* VARIABLES FOR INTERNAL USE
*/
/**
* Stores session ID while pazpar2 is running.
* @var string
*/
protected $pazpar2SessionID;
/**
* Returns URL for pazpar2 search command.
*
* @return string
*/
protected function pazpar2SearchURL()
{
return $this->appendSessionID(parent::pazpar2SearchURL());
}
/**
* Appends the session ID to $URL.
*
* @param string $URL
* @return string
*/
protected function appendSessionID($URL)
{
return $URL . '&session=' . $this->pazpar2SessionID;
}
/**
* Returns URL for a status request of the current pazpar2 session.
*
* @return string
*/
protected function pazpar2StatURL()
{
return $this->appendSessionID(parent::pazpar2StatURL());
}
/**
* Returns URL for downloading pazpar2 results.
* The parameters can be used to give the the start record
* as well as the number of records required.
*
* TYPO3 typically starts running into out of memory errors when fetching
* around 1000 records in one go with a 128MB memory limit for PHP.
*
* @param int $start index of first record to retrieve (optional, default: 0)
* @param int $num number of records to retrieve (optional, default: 500)
* @return string
*/
protected function pazpar2ShowURL($start=0, $num=500)
{
return $this->appendSessionID(parent::pazpar2ShowURL($start, $num));
}
/**
* Initialise the pazpar2 session and store the session ID in $pazpar2SessionID.
*
* @return bool TRUE when initialisation was successful
*/
protected function initialiseSession()
{