Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A20160606 #716

Merged
merged 2 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 58 additions & 29 deletions app/SymfonyRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@
class Requirement
{
private $fulfilled;

private $testMessage;

private $helpText;

private $helpHtml;

private $optional;

/**
Expand All @@ -49,11 +53,11 @@ class Requirement
*/
public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false)
{
$this->fulfilled = (bool) $fulfilled;
$this->testMessage = (string) $testMessage;
$this->helpHtml = (string) $helpHtml;
$this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText;
$this->optional = (bool) $optional;
$this->fulfilled = (bool)$fulfilled;
$this->testMessage = (string)$testMessage;
$this->helpHtml = (string)$helpHtml;
$this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string)$helpText;
$this->optional = (bool)$optional;
}

/**
Expand Down Expand Up @@ -128,8 +132,15 @@ class PhpIniRequirement extends Requirement
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
* @param bool $optional Whether this is only an optional recommendation not a mandatory requirement
*/
public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false)
{
public function __construct(
$cfgName,
$evaluation,
$approveCfgAbsence = false,
$testMessage = null,
$helpHtml = null,
$helpText = null,
$optional = false
) {
$cfgValue = ini_get($cfgName);

if (is_callable($evaluation)) {
Expand Down Expand Up @@ -157,7 +168,8 @@ public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $
$fulfilled = $evaluation == $cfgValue;
}

parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional);
parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml,
$helpText, $optional);
}
}

Expand All @@ -168,7 +180,7 @@ public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $
*/
class RequirementCollection implements IteratorAggregate
{
private $requirements = array();
private $requirements = [];

/**
* Gets the current RequirementCollection as an Iterator.
Expand Down Expand Up @@ -229,9 +241,16 @@ public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText
* @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived)
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
*/
public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
{
$this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false));
public function addPhpIniRequirement(
$cfgName,
$evaluation,
$approveCfgAbsence = false,
$testMessage = null,
$helpHtml = null,
$helpText = null
) {
$this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText,
false));
}

/**
Expand All @@ -247,9 +266,16 @@ public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence =
* @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived)
* @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
*/
public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null)
{
$this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true));
public function addPhpIniRecommendation(
$cfgName,
$evaluation,
$approveCfgAbsence = false,
$testMessage = null,
$helpHtml = null,
$helpText = null
) {
$this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText,
true));
}

/**
Expand Down Expand Up @@ -279,7 +305,7 @@ public function all()
*/
public function getRequirements()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if (!$req->isOptional()) {
$array[] = $req;
Expand All @@ -296,7 +322,7 @@ public function getRequirements()
*/
public function getFailedRequirements()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && !$req->isOptional()) {
$array[] = $req;
Expand All @@ -313,7 +339,7 @@ public function getFailedRequirements()
*/
public function getRecommendations()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if ($req->isOptional()) {
$array[] = $req;
Expand All @@ -330,7 +356,7 @@ public function getRecommendations()
*/
public function getFailedRecommendations()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && $req->isOptional()) {
$array[] = $req;
Expand Down Expand Up @@ -393,7 +419,8 @@ public function __construct()
sprintf('You are running PHP version "<strong>%s</strong>", but Symfony needs at least PHP "<strong>%s</strong>" to run.
Before using Symfony, upgrade your PHP installation, preferably to the latest version.',
$installedPhpVersion, self::REQUIRED_PHP_VERSION),
sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION, $installedPhpVersion)
sprintf('Install PHP %s or newer (installed version is %s)', self::REQUIRED_PHP_VERSION,
$installedPhpVersion)
);

$this->addRequirement(
Expand All @@ -406,7 +433,7 @@ public function __construct()
is_dir(__DIR__.'/../vendor/composer'),
'Vendor libraries must be installed',
'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
'Then run "<strong>php composer.phar install</strong>" to install them.'
'Then run "<strong>php composer.phar install</strong>" to install them.'
);

$cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache';
Expand All @@ -432,7 +459,7 @@ public function __construct()
);

if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) {
$timezones = array();
$timezones = [];
foreach (DateTimeZone::listAbbreviations() as $abbreviations) {
foreach ($abbreviations as $abbreviation) {
$timezones[$abbreviation['timezone_id']] = true;
Expand All @@ -441,7 +468,8 @@ public function __construct()

$this->addRequirement(
isset($timezones[@date_default_timezone_get()]),
sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()),
sprintf('Configured default timezone "%s" must be supported by your installation of PHP',
@date_default_timezone_get()),
'Your default timezone is not supported by PHP. Check for typos in your <strong>php.ini</strong> file and have a look at the list of deprecated timezones at <a href="http://php.net/manual/en/timezones.others.php">http://php.net/manual/en/timezones.others.php</a>.'
);
}
Expand Down Expand Up @@ -528,7 +556,7 @@ function_exists('simplexml_import_dom'),
);
}

$pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null;
$pcreVersion = defined('PCRE_VERSION') ? (float)PCRE_VERSION : null;

$this->addRequirement(
null !== $pcreVersion,
Expand Down Expand Up @@ -590,7 +618,8 @@ function_exists('simplexml_import_dom'),
);

$this->addRecommendation(
(version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0', '<'))
(version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0',
'<'))
||
version_compare($installedPhpVersion, '5.4.8', '>='),
'You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909',
Expand Down Expand Up @@ -697,8 +726,7 @@ function_exists('posix_isatty'),
||
(extension_loaded('xcache') && ini_get('xcache.cacher'))
||
(extension_loaded('wincache') && ini_get('wincache.ocenabled'))
;
(extension_loaded('wincache') && ini_get('wincache.ocenabled'));

$this->addRecommendation(
$accelerator,
Expand Down Expand Up @@ -732,7 +760,8 @@ class_exists('PDO'),
$drivers = PDO::getAvailableDrivers();
$this->addRecommendation(
count($drivers) > 0,
sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'),
sprintf('PDO should have some drivers installed (currently available: %s)',
count($drivers) ? implode(', ', $drivers) : 'none'),
'Install <strong>PDO drivers</strong> (mandatory for Doctrine).'
);
}
Expand All @@ -758,7 +787,7 @@ protected function getRealpathCacheSize()
case 'k':
return $size * 1024;
default:
return (int) $size;
return (int)$size;
}
}
}
8 changes: 4 additions & 4 deletions app/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

echo '> Checking Symfony requirements:'.PHP_EOL.' ';

$messages = array();
$messages = [];
foreach ($symfonyRequirements->getRequirements() as $req) {
/** @var $req Requirement */
if ($helpText = get_error_message($req, $lineSize)) {
Expand Down Expand Up @@ -99,18 +99,18 @@ function echo_title($title, $style = null)
function echo_style($style, $message)
{
// ANSI color codes
$styles = array(
$styles = [
'reset' => "\033[0m",
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m",
'error' => "\033[37;41m",
'success' => "\033[37;42m",
'title' => "\033[34m",
);
];
$supports = has_color_support();

echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
echo ($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
}

function echo_block($style, $title, $message)
Expand Down
3 changes: 3 additions & 0 deletions app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ security:
admin:
password: x61Ey612Kl2gpFL56FT9weDnpSo4AV8j8+qx2AuTHdRyY036xxzTTrw10Wq3+4qQyB+XURPWx1ONxp3Y3pB37A==
roles: 'ROLE_ADMIN'

parameters:
partkeepr.parts.internalPartNumberUnique: true
8 changes: 8 additions & 0 deletions app/config/parameters.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ $container->setParameter('partkeepr.users.limit', false);
*/
$container->setParameter('partkeepr.parts.limit', false);

/**
* Defines if the internal part number must be unique or not. Note that empty internal part numbers aren't checked -
* if you require to enforce an internal part number, also set the field internalPartNumber to mandatory.
*
* Defaults to false
*/
$container->setParameter('partkeepr.parts.internalPartNumberUnique', false);

/**
* Specifies the PartKeepr data directory
*/
Expand Down
3 changes: 1 addition & 2 deletions src/PartKeepr/DoctrineReflectionBundle/Filter/Sorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function setDirection($direction)
{
$this->direction = $direction;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use Dunglas\ApiBundle\Action\ActionUtilTrait;
use Dunglas\ApiBundle\Api\ResourceInterface;
use Dunglas\ApiBundle\Exception\RuntimeException;
use PartKeepr\PartBundle\Entity\Part;
use PartKeepr\PartBundle\Exceptions\InternalPartNumberNotUniqueException;
use PartKeepr\PartBundle\Exceptions\PartLimitExceededException;
use PartKeepr\PartBundle\Services\PartService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\SerializerInterface;

class PostAction
class PartPostAction
{
use ActionUtilTrait;

Expand Down Expand Up @@ -39,25 +41,35 @@ public function __construct(
*
* @throws RuntimeException
* @throws PartLimitExceededException
* @throws InternalPartNumberNotUniqueException
*
* @return mixed
*/
public function __invoke(Request $request)
{
/*
* @var $resourceType ResourceInterface
*/
if ($this->partService->checkPartLimit()) {
throw new PartLimitExceededException();
}

/**
* @var $resourceType ResourceInterface
*/
list($resourceType, $format) = $this->extractAttributes($request);

return $this->serializer->deserialize(
/**
* @var $part Part
*/
$part = $this->serializer->deserialize(
$request->getContent(),
$resourceType->getEntityClass(),
$format,
$resourceType->getDenormalizationContext()
);

if (!$this->partService->isInternalPartNumberUnique($part->getInternalPartNumber())) {
throw new InternalPartNumberNotUniqueException();
}

return $part;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace PartKeepr\PartBundle\Exceptions;

use PartKeepr\CoreBundle\Exceptions\TranslatableException;

class InternalPartNumberNotUniqueException extends TranslatableException
{
public function getMessageKey()
{
return 'The internal part number is already used';
}
}
Loading