-
Notifications
You must be signed in to change notification settings - Fork 52
PrimitiveRule, изменение внутренностей Form::addRule, checkRules и т.д. #169
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/*************************************************************************** | ||
* Copyright (C) 2008 by Konstantin V. Arkhipov * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU Lesser General Public License as * | ||
* published by the Free Software Foundation; either version 3 of the * | ||
* License, or (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
/** | ||
* @ingroup Primitives | ||
**/ | ||
final class PrimitiveRule extends BasePrimitive | ||
{ | ||
/** | ||
* @var LogicalObject | ||
*/ | ||
private $expression = null; | ||
|
||
public function __clone() | ||
{ | ||
$this->expression = clone $this->expression; | ||
} | ||
|
||
/** | ||
* @return PrimitiveRule | ||
**/ | ||
public function setExpression(LogicalObject $exp) | ||
{ | ||
$this->expression = $exp; | ||
|
||
return $this; | ||
} | ||
|
||
public function import($scope, Form $form = null) | ||
{ | ||
Assert::isNotNull($form, 'expects Form as 2-nd argument'); | ||
Assert::isNotNull($this->expression, 'setExpression first'); | ||
|
||
return $this->expression->toBoolean($form) === true; | ||
} | ||
} | ||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,6 @@ | |
**/ | ||
abstract class RegulatedForm extends PlainForm | ||
{ | ||
protected $rules = array(); // forever | ||
protected $violated = array(); // rules | ||
|
||
/** | ||
* @throws WrongArgumentException | ||
* @return Form | ||
|
@@ -28,9 +25,9 @@ public function addRule($name, LogicalObject $rule) | |
{ | ||
Assert::isString($name); | ||
|
||
$this->rules[$name] = $rule; | ||
|
||
return $this; | ||
return $this->add( | ||
Primitive::rule($name)->setExpression($rule) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -39,32 +36,17 @@ public function addRule($name, LogicalObject $rule) | |
**/ | ||
public function dropRuleByName($name) | ||
{ | ||
if (isset($this->rules[$name])) { | ||
unset($this->rules[$name]); | ||
return $this; | ||
$rule = $this->get($name); | ||
if (!$rule instanceof PrimitiveRule) { | ||
throw new MissingElementException("no such PrimitiveRule with '{$name}' name"); | ||
} | ||
|
||
throw new MissingElementException( | ||
"no such rule with '{$name}' name" | ||
); | ||
return $this->drop($name); | ||
} | ||
|
||
public function ruleExists($name) | ||
{ | ||
return isset($this->rules[$name]); | ||
} | ||
|
||
/** | ||
* @return Form | ||
**/ | ||
public function checkRules() | ||
{ | ||
foreach ($this->rules as $name => $logicalObject) { | ||
if (!$logicalObject->toBoolean($this)) | ||
$this->violated[$name] = Form::WRONG; | ||
} | ||
|
||
return $this; | ||
return $this->primitiveExists($name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
&& $this->get($name) instanceof PrimitiveRule; | ||
} | ||
} | ||
?> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
аргументы не плохо бы привести к одному знаменателю
ну и везде в Form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В этом методе нет аргументов. Внутренние переменные вполне прилично называются. Про Form не понял.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ну это уже обсуждалось вроде там откуда это взято.
про Form -- во всем файле раз уж так его архитектуру меняем.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так это там архитектура меняется, а тут оно rules, PrimitiveRule и только вокруг них. Опять же никто не решил к какому общему названию приходить. И опять же это локальные переменные внутри функции - они по названию говорят что значат и это хорошо.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
согласен. погоды не делает. никто не решил но уже 3 высказались )