Overview

Namespaces

  • Racoon
    • Api
      • Auth
      • Exception
      • Response
        • Format
        • Generate
      • Schema

Classes

  • Racoon\Api\App
  • Racoon\Api\Auth\ApiKeyAuthenticator
  • Racoon\Api\Auth\NoAuthenticator
  • Racoon\Api\Controller
  • Racoon\Api\Request
  • Racoon\Api\Response\Format\JsonFormatter
  • Racoon\Api\Response\Generate\DetailedResponse
  • Racoon\Api\Schema\Item
  • Racoon\Api\Schema\Schema
  • Racoon\Api\Schema\Translator

Interfaces

  • Racoon\Api\Auth\AuthInterface
  • Racoon\Api\Response\Format\FormatterInterface
  • Racoon\Api\Response\Generate\GeneratorInterface

Exceptions

  • Racoon\Api\Exception\AuthenticationException
  • Racoon\Api\Exception\Exception
  • Racoon\Api\Exception\InvalidArgumentException
  • Racoon\Api\Exception\InvalidJsonException
  • Racoon\Api\Exception\InvalidRouteException
  • Racoon\Api\Exception\NotFoundException
  • Racoon\Api\Exception\ResponseFormattingException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Racoon\Api\Schema;
  4: 
  5: 
  6: use TomWright\Validator\Constraint\BoolConstraint;
  7: use TomWright\Validator\Constraint\ConstraintGroup;
  8: use TomWright\Validator\Constraint\ConstraintGroupTranslator;
  9: use TomWright\Validator\Constraint\EmailConstraint;
 10: use TomWright\Validator\Constraint\IntConstraint;
 11: use TomWright\Validator\Constraint\NotNullConstraint;
 12: use TomWright\Validator\Constraint\NullConstraint;
 13: use TomWright\Validator\Constraint\StringConstraint;
 14: use TomWright\Validator\Constraint\ArrayConstraint;
 15: use TomWright\Validator\Constraint\ObjectConstraint;
 16: 
 17: class Translator
 18: {
 19: 
 20:     /**
 21:      * @var Item
 22:      */
 23:     protected $item;
 24: 
 25:     /**
 26:      * @var string
 27:      */
 28:     protected $propertyName;
 29: 
 30:     /**
 31:      * @var string
 32:      */
 33:     protected $readableName;
 34: 
 35:     /**
 36:      * @var ConstraintGroupTranslator
 37:      */
 38:     protected $currentConstraintGroup;
 39: 
 40: 
 41:     /**
 42:      * @return Item
 43:      */
 44:     public function getItem()
 45:     {
 46:         if (! is_object($this->item)) {
 47:             $this->item = new Item($this->propertyName, $this->readableName);
 48:         }
 49:         return $this->item;
 50:     }
 51: 
 52: 
 53:     /**
 54:      * @return Item
 55:      */
 56:     public function returnItem()
 57:     {
 58:         if ($this->hasCurrentConstraintGroup()) {
 59:             $this->getItem()->getValidator()->addConstraintGroup($this->getCurrentConstraintGroup());
 60:         }
 61:         return $this->getItem();
 62:     }
 63: 
 64: 
 65:     /**
 66:      * An OR, but OR is a keyword.
 67:      * @return $this
 68:      */
 69:     public function newConstraintGroup()
 70:     {
 71:         if ($this->hasCurrentConstraintGroup()) {
 72:             $this->getItem()->getValidator()->addConstraintGroup($this->getCurrentConstraintGroup());
 73:             $this->currentConstraintGroup = null;
 74:         }
 75:         return $this;
 76:     }
 77: 
 78: 
 79:     /**
 80:      * @return ConstraintGroupTranslator
 81:      */
 82:     public function getCurrentConstraintGroup()
 83:     {
 84:         if (! $this->hasCurrentConstraintGroup()) {
 85:             $this->currentConstraintGroup = ConstraintGroupTranslator::create();
 86:         }
 87:         return $this->currentConstraintGroup;
 88:     }
 89: 
 90: 
 91:     /**
 92:      * @return mixed
 93:      */
 94:     public function hasCurrentConstraintGroup()
 95:     {
 96:         return (is_object($this->currentConstraintGroup));
 97:     }
 98: 
 99: 
100:     /**
101:      * Alias of newConstraintGroup.
102:      * @return Translator
103:      */
104:     public function alt()
105:     {
106:         return $this->newConstraintGroup();
107:     }
108: 
109: 
110:     /**
111:      * @param string $propertyName
112:      * @param string|null $readableName
113:      * @return static
114:      */
115:     public static function item($propertyName, $readableName = null)
116:     {
117:         $translator = new static();
118: 
119:         $translator->propertyName = $propertyName;
120:         if ($readableName === null) {
121:             $readableName = $propertyName;
122:         }
123:         $translator->readableName = $readableName;
124: 
125:         return $translator;
126:     }
127: 
128: 
129:     /**
130:      * @return $this
131:      */
132:     public function required()
133:     {
134:         $this->getItem()->setRequired(true);
135:         return $this;
136:     }
137: 
138: 
139:     /**
140:      * @return $this
141:      */
142:     public function optional()
143:     {
144:         $this->getItem()->setRequired(false);
145:         return $this;
146:     }
147: 
148: 
149:     /**
150:      * @param ConstraintGroup|ConstraintGroupTranslator|null $group
151:      * @return $this
152:      */
153:     public function optionalConstraintGroup(ConstraintGroup $group = null)
154:     {
155:         $this->getItem()->setOptionalConstraintGroup($group);
156:         return $this;
157:     }
158: 
159: 
160:     /**
161:      * @param null|bool $requiredValue
162:      * @return $this
163:      */
164:     public function isBool($requiredValue = null)
165:     {
166:         $this->getCurrentConstraintGroup()->isBool($requiredValue);
167:         return $this;
168:     }
169: 
170: 
171:     /**
172:      * @return Translator
173:      */
174:     public function isTrue()
175:     {
176:         $this->getCurrentConstraintGroup()->isTrue();
177:         return $this;
178:     }
179: 
180: 
181:     /**
182:      * @return Translator
183:      */
184:     public function isFalse()
185:     {
186:         $this->getCurrentConstraintGroup()->isFalse();
187:         return $this;
188:     }
189: 
190: 
191:     /**
192:      * @param null $minLength
193:      * @param null $maxLength
194:      * @return $this
195:      */
196:     public function isString($minLength = null, $maxLength = null)
197:     {
198:         $this->getCurrentConstraintGroup()->isString($minLength, $maxLength);
199:         return $this;
200:     }
201: 
202: 
203:     /**
204:      * @param null|int $minValue
205:      * @param null|int $maxValue
206:      * @return $this
207:      */
208:     public function isInt($minValue = null, $maxValue = null)
209:     {
210:         $this->getCurrentConstraintGroup()->isInt($minValue, $maxValue);
211:         return $this;
212:     }
213: 
214: 
215:     /**
216:      * @param null|float $minValue
217:      * @param null|float $maxValue
218:      * @return $this
219:      */
220:     public function isFloat($minValue = null, $maxValue = null)
221:     {
222:         $this->getCurrentConstraintGroup()->isFloat($minValue, $maxValue);
223:         return $this;
224:     }
225: 
226: 
227:     /**
228:      * @param null|int|float $minValue
229:      * @param null|int|float $maxValue
230:      * @return $this
231:      */
232:     public function isNumeric($minValue = null, $maxValue = null)
233:     {
234:         $this->getCurrentConstraintGroup()->isNumeric($minValue, $maxValue);
235:         return $this;
236:     }
237: 
238: 
239:     /**
240:      * @return $this
241:      */
242:     public function isNull()
243:     {
244:         $this->getCurrentConstraintGroup()->isNull();
245:         return $this;
246:     }
247: 
248: 
249:     /**
250:      * @return $this
251:      */
252:     public function notNull()
253:     {
254:         $this->getCurrentConstraintGroup()->notNull();
255:         return $this;
256:     }
257: 
258: 
259:     /**
260:      * @return $this
261:      */
262:     public function isEmail()
263:     {
264:         $this->getCurrentConstraintGroup()->isEmail();
265:         return $this;
266:     }
267: 
268: 
269:     /**
270:      * @return $this
271:      */
272:     public function isArray()
273:     {
274:         $this->getCurrentConstraintGroup()->isArray();
275:         return $this;
276:     }
277: 
278: 
279:     /**
280:      * @param null|string $requiredClass
281:      * @return $this
282:      */
283:     public function isObject($requiredClass = null)
284:     {
285:         $this->getCurrentConstraintGroup()->isObject($requiredClass);
286:         return $this;
287:     }
288: 
289: }
API documentation generated by ApiGen