/**
  * @throws WrongArgumentException
  * @return PrimitiveEnumeration
  **/
 public function of($class)
 {
     $className = $this->guessClassName($class);
     Assert::classExists($className);
     Assert::isInstance($className, Enumeration::class);
     $this->className = $className;
     return $this;
 }
Example #2
0
 public function send(Message $message)
 {
     if (!$this->queue) {
         throw new WrongStateException('you must set the queue first');
     }
     Assert::isInstance($message, 'TextMessage');
     $this->getStream()->write($message->getTimestamp()->toString() . "\t" . str_replace(PHP_EOL, ' ', $message->getText()) . PHP_EOL);
 }
 /**
  * @return PrimitiveRegistryList
  **/
 public function setValue($value)
 {
     if ($value) {
         Assert::isArray($value);
         Assert::isInstance(current($value), Registry::class);
     }
     $this->value = $value;
     return $this;
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, AMQPQueueConfig::class);
     $bitmask = parent::getBitmask($config);
     if ($config->getExclusive()) {
         $bitmask = $bitmask | AMQP_EXCLUSIVE;
     }
     return $bitmask;
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, AMQPExchangeConfig::class);
     $bitmask = parent::getBitmask($config);
     if ($config->getInternal()) {
         $bitmask = $bitmask | AMQP_INTERNAL;
     }
     return $bitmask;
 }
Example #6
0
 public function importValue($value)
 {
     if ($value) {
         Assert::isInstance($value, $this->className);
         //			Assert::isEqual(get_class($value), $this->className);
     } else {
         return parent::importValue(null);
     }
     return $this->import(array($this->getName() => $value->getId()));
 }
 public function uncache()
 {
     foreach ($this->classNameMap as $className => $tags) {
         $dao = ClassUtils::callStaticMethod("{$className}::dao");
         /* @var $dao StorableDAO */
         $worker = Cache::worker($dao);
         Assert::isInstance($worker, TaggableDaoWorker::class);
         $worker->expireTags($tags);
     }
 }
 public function compare($one, $two)
 {
     Assert::isInstance($one, Date::class);
     Assert::isInstance($two, Date::class);
     $stamp1 = $one->toStamp();
     $stamp2 = $two->toStamp();
     if ($stamp1 == $stamp2) {
         return 0;
     }
     return $stamp1 < $stamp2 ? -1 : 1;
 }
 public function compare($one, $two)
 {
     Assert::isInstance($one, Identifiable::class);
     Assert::isInstance($two, Identifiable::class);
     $oneId = $one->getId();
     $twoId = $two->getId();
     if ($oneId === $twoId) {
         return 0;
     }
     return $oneId < $twoId ? -1 : 1;
 }
Example #10
0
 /**
  * @throws WrongArgumentException
  * @return AMQPPool
  **/
 public function addLink($name, AMQP $amqp)
 {
     if (isset($this->pool[$name])) {
         throw new WrongArgumentException("amqp link with name '{$name}' already registered");
     }
     if ($this->pool) {
         Assert::isInstance($amqp, current($this->pool));
     }
     $this->pool[$name] = $amqp;
     return $this;
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, AMQPOutgoingMessage::class);
     $bitmask = 0;
     if ($config->getMandatory()) {
         $bitmask = $bitmask | AMQP_MANDATORY;
     }
     if ($config->getImmediate()) {
         $bitmask = $bitmask | AMQP_IMMEDIATE;
     }
     return $bitmask;
 }
Example #12
0
 public function cloneInnerBuilder($property)
 {
     $mapping = $this->getFormMapping();
     Assert::isIndexExists($mapping, $property);
     $primitive = $mapping[$property];
     Assert::isInstance($primitive, PrimitiveForm::class);
     $result = new $this($primitive->getProto());
     if (isset($this->limitedPropertiesList[$primitive->getName()])) {
         $result->setLimitedPropertiesList($this->limitedPropertiesList[$primitive->getName()]);
     }
     return $result;
 }
Example #13
0
 public static function getIdsArray($objectsList)
 {
     $out = [];
     if (!$objectsList) {
         return $out;
     }
     Assert::isInstance(current($objectsList), Identifiable::class, 'only identifiable lists accepted');
     foreach ($objectsList as $object) {
         $out[] = $object->getId();
     }
     return $out;
 }
Example #14
0
 /**
  * @return Form
  **/
 public function fillOwn($object, &$result)
 {
     Assert::isInstance($result, Form::class);
     foreach ($this->getFormMapping() as $primitive) {
         if ($primitive instanceof PrimitiveForm && $result->exists($primitive->getName()) && $primitive->isComposite()) {
             Assert::isEqual($primitive->getProto(), $result->get($primitive->getName())->getProto());
             continue;
         }
         $result->add($primitive);
     }
     $result = parent::fillOwn($object, $result);
     $result->setProto($this->proto);
     return $result;
 }
Example #15
0
 public final function validate($object, $form, $previousObject = null)
 {
     if (is_array($object)) {
         return $this->validateList($object, $form, $previousObject);
     }
     Assert::isInstance($object, $this->className());
     Assert::isInstance($form, Form::class);
     if ($previousObject) {
         Assert::isInstance($previousObject, $this->className());
     }
     if ($this->baseProto()) {
         $this->baseProto()->validate($object, $form, $previousObject);
     }
     return $this->validateSelf($object, $form, $previousObject);
 }
Example #16
0
 public static function getAgeByBirthDate(Date $birthDate, $actualDate = null)
 {
     if ($actualDate) {
         Assert::isInstance($actualDate, Date::class);
     } else {
         $actualDate = Date::makeToday();
     }
     $result = $actualDate->getYear() - $birthDate->getYear();
     if ($actualDate->getMonth() < $birthDate->getMonth() || $actualDate->getMonth() == $birthDate->getMonth() && $actualDate->getDay() < $birthDate->getDay()) {
         // - Happy birthday?
         // - Happy go to hell. Not yet in this year.
         --$result;
     }
     return $result;
 }
 public function uncache()
 {
     foreach ($this->classNameMap as $className => $uncaches) {
         list($idKeys, $tags) = $uncaches;
         $dao = ClassUtils::callStaticMethod("{$className}::dao");
         /* @var $dao StorableDAO */
         $worker = Cache::worker($dao);
         Assert::isInstance($worker, TaggableDaoWorker::class);
         $worker->expireTags($tags);
         foreach ($idKeys as $key) {
             Cache::me()->mark($className)->delete($key);
         }
         $dao->uncacheLists();
     }
 }
Example #18
0
 public function importValue($value)
 {
     if ($value !== null) {
         Assert::isArray($value);
     } else {
         return null;
     }
     $result = true;
     $resultValue = [];
     foreach ($value as $id => $form) {
         Assert::isInstance($form, Form::class);
         $resultValue[$id] = $form;
         if ($form->getErrors()) {
             $result = false;
         }
     }
     $this->value = $resultValue;
     return $result;
 }
 protected function call($method, DTOMessage $request, $resultClass)
 {
     $requestDto = $request->makeDto();
     Assert::isInstance($requestDto, DTOClass::class);
     if (defined('__LOCAL_DEBUG__') && !defined('SIMPLE_TEST')) {
         // self-validation
         $form = ObjectToFormConverter::create($request->entityProto())->make($request);
         Assert::isTrue(!$form->getErrors() && $request->entityProto()->validate($request, $form), Assert::dumpArgument($request));
     }
     try {
         try {
             $resultDto = $this->getSoapClient()->{$method}($requestDto);
         } catch (BaseException $e) {
             if (get_class($e) == BaseException::class) {
                 throw new SoapFault('Server', get_class($e) . ': ' . $e->getMessage());
             } else {
                 $this->logCall();
                 throw $e;
             }
         }
     } catch (SoapFault $e) {
         $this->logCall();
         throw self::convertSoapFault($e);
     }
     $this->logCall();
     if (!$resultClass) {
         Assert::isNull($resultDto);
         $result = null;
     } else {
         Assert::isInstance($resultDto, DTOClass::class);
         Assert::isEqual($resultDto->entityProto()->className(), $resultClass);
         $form = DTOToFormImporter::create($resultDto->entityProto())->make($resultDto);
         Assert::isTrue(!$form->getErrors(), Assert::dumpArgument($resultDto));
         $result = $resultDto->makeObject($form);
         Assert::isInstance($result, DTOMessage::class);
         Assert::isEqual(get_class($result), $resultClass);
         Assert::isTrue($result->entityProto()->validate($result, $form), Assert::dumpArgument($result));
     }
     return $result;
 }
Example #20
0
 public function __construct(EntityProto $proto, $object)
 {
     Assert::isInstance($object, Form::class);
     return parent::__construct($proto, $object);
 }
Example #21
0
 /**
  * @return Criteria
  **/
 public function dropProjectionByType($dropTypes)
 {
     Assert::isInstance($this->projection, ProjectionChain::class);
     $this->projection->dropByType($dropTypes);
     return $this;
 }
Example #22
0
 /**
  * @return DaoSynchronizer
  **/
 public function setSlave(GenericDAO $slave)
 {
     Assert::isInstance($slave, ProtoDAO::class);
     return parent::setSlave($slave);
 }
 public function import($scope)
 {
     if (!$this->className) {
         throw new WrongStateException("no class defined for PrimitiveIdentifier '{$this->name}'");
     }
     $className = $this->className;
     if (isset($scope[$this->name]) && $scope[$this->name] instanceof $className) {
         $value = $scope[$this->name];
         $this->raw = $this->actualExportValue($value);
         $this->setValue($value);
         return $this->imported = true;
     }
     $result = parent::import($scope);
     if ($result === true) {
         try {
             $result = $this->actualImportValue($this->value);
             Assert::isInstance($result, $className);
             $this->value = $result;
             return true;
         } catch (WrongArgumentException $e) {
             // not imported
         } catch (ObjectNotFoundException $e) {
             // not imported
         }
         $this->value = null;
         return false;
     }
     return $result;
 }
Example #24
0
 protected function checkObjectType(Identifiable $object)
 {
     Assert::isInstance($object, $this->getObjectName(), 'strange object given, i can not inject it');
     //		Assert::isSame(get_class($object), $this->getObjectName(), 'strange object given, i can not inject it');
 }
Example #25
0
 /**
  * @param $uncacher UncacherGenericDAO same as self class
  *
  * @return UncacherBase (this)
  */
 public function merge(UncacherBase $uncacher)
 {
     Assert::isInstance($uncacher, self::class);
     return $this->mergeSelf($uncacher);
 }
Example #26
0
 /**
  * @return TextFileReceiver
  **/
 public function setQueue(MessageQueue $queue)
 {
     Assert::isInstance($queue, TextFileQueue::class);
     $this->queue = $queue;
     return $this;
 }
Example #27
0
 public function __construct(Identifiable $parent, GenericDAO $dao, $lazy = true)
 {
     Assert::isBoolean($lazy);
     $this->parent = $parent;
     $this->lazy = $lazy;
     $this->dao = $dao;
     Assert::isInstance($dao->getObjectName(), Identifiable::class);
     $this->comparator = SerializedObjectComparator::me();
 }
Example #28
0
 /**
  * @return PrimitiveIdentifier
  **/
 public static function prototypedIdentifier($class, $name = null)
 {
     Assert::isInstance($class, DAOConnected::class);
     $dao = is_string($class) ? call_user_func([$class, 'dao']) : $class->dao();
     return self::prototyped($class, $dao->getIdName(), $name);
 }
 /**
  * @param $uncacher UncacherNullDaoWorker same as self class
  *
  * @return UncacherBase (this)
  */
 public function merge(UncacherBase $uncacher)
 {
     Assert::isInstance($uncacher, get_class($this));
     return $this->mergeSelf($uncacher);
 }
 public function setDefault($default)
 {
     Assert::isInstance($default, $this->className);
     $this->default = $default;
     return $this;
 }