Ejemplo n.º 1
0
 public static function generateLinks(array $classes)
 {
     $links = [];
     foreach ($classes as $class) {
         Assert::isInstance($class, 'MetaClass');
         foreach ($class->getProperties() as $property) {
             if ($property->getType() instanceof ObjectType && $property->getType()->getClassName() && $property->getRelation()) {
                 switch ($property->getRelation()->getId()) {
                     case MetaRelation::ONE_TO_ONE:
                         $rel = ' -- ';
                         break;
                     case MetaRelation::ONE_TO_MANY:
                         $rel = ' *-- ';
                         break;
                     case MetaRelation::MANY_TO_MANY:
                         $rel = ' *--* ';
                         break;
                     default:
                         throw new WrongStateException();
                         break;
                 }
                 $links[] = $class->getName() . $rel . $property->getType()->getClassName() . "\n";
             }
         }
         $links = array_unique($links);
     }
     return implode("", $links) . "\n";
 }
 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 = $value->getId();
         $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;
 }
 /**
  * @param string $path
  * @return DBTestCreator
  */
 public function setSchemaPath($path)
 {
     require $path;
     Assert::isTrue(isset($schema));
     Assert::isInstance($schema, 'DBSchema');
     $this->schema = $schema;
     return $this;
 }
 /**
  * @throws WrongArgumentException
  * @return PrimitiveEnum
  **/
 public function of($class)
 {
     $className = $this->guessClassName($class);
     Assert::classExists($className);
     Assert::isInstance($className, 'Enum');
     $this->className = $className;
     return $this;
 }
 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);
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, 'AMQPExchangeConfig');
     $bitmask = parent::getBitmask($config);
     if ($config->getInternal()) {
         $bitmask = $bitmask | AMQP_INTERNAL;
     }
     return $bitmask;
 }
 /**
  * @return PrimitiveEnumList
  **/
 public function setValue($value)
 {
     if ($value) {
         Assert::isArray($value);
         Assert::isInstance(current($value), 'Enum');
     }
     $this->value = $value;
     return $this;
 }
 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');
     $this->comparator = SerializedObjectComparator::me();
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, 'AMQPQueueConfig');
     $bitmask = parent::getBitmask($config);
     if ($config->getExclusive()) {
         $bitmask = $bitmask | AMQP_EXCLUSIVE;
     }
     return $bitmask;
 }
 public function compare($one, $two)
 {
     Assert::isInstance($one, 'Identifiable');
     Assert::isInstance($two, 'Identifiable');
     $oneId = $one->getId();
     $twoId = $two->getId();
     if ($oneId === $twoId) {
         return 0;
     }
     return $oneId < $twoId ? -1 : 1;
 }
 /**
  * @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 compare($one, $two)
 {
     Assert::isInstance($one, 'Date');
     Assert::isInstance($two, 'Date');
     $stamp1 = $one->toStamp();
     $stamp2 = $two->toStamp();
     if ($stamp1 == $stamp2) {
         return 0;
     }
     return $stamp1 < $stamp2 ? -1 : 1;
 }
 public function getBitmask($config)
 {
     Assert::isInstance($config, 'AMQPOutgoingMessage');
     $bitmask = 0;
     if ($config->getMandatory()) {
         $bitmask = $bitmask | AMQP_MANDATORY;
     }
     if ($config->getImmediate()) {
         $bitmask = $bitmask | AMQP_IMMEDIATE;
     }
     return $bitmask;
 }
 public function cloneInnerBuilder($property)
 {
     $mapping = $this->getFormMapping();
     Assert::isIndexExists($mapping, $property);
     $primitive = $mapping[$property];
     Assert::isInstance($primitive, 'PrimitiveForm');
     $result = new $this($primitive->getProto());
     if (isset($this->limitedPropertiesList[$primitive->getName()])) {
         $result->setLimitedPropertiesList($this->limitedPropertiesList[$primitive->getName()]);
     }
     return $result;
 }
 public static function getIdsArray($objectsList)
 {
     $out = array();
     if (!$objectsList) {
         return $out;
     }
     Assert::isInstance(current($objectsList), 'Identifiable', 'only identifiable lists accepted');
     foreach ($objectsList as $object) {
         $out[] = $object->getId();
     }
     return $out;
 }
 /**
  * @return Form
  **/
 public function fillOwn($object, &$result)
 {
     Assert::isInstance($result, 'Form');
     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;
 }
 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');
     if ($previousObject) {
         Assert::isInstance($previousObject, $this->className());
     }
     if ($this->baseProto()) {
         $this->baseProto()->validate($object, $form, $previousObject);
     }
     return $this->validateSelf($object, $form, $previousObject);
 }
 public static function getAgeByBirthDate(Date $birthDate, $actualDate = null)
 {
     if ($actualDate) {
         Assert::isInstance($actualDate, 'Date');
     } 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 importValue($value)
 {
     if ($value !== null) {
         Assert::isArray($value);
     } else {
         return null;
     }
     $result = true;
     $resultValue = array();
     foreach ($value as $id => $form) {
         Assert::isInstance($form, 'Form');
         $resultValue[$id] = $form;
         if ($form->getErrors()) {
             $result = false;
         }
     }
     $this->value = $resultValue;
     return $result;
 }
 public function __construct(EntityProto $proto, &$object)
 {
     Assert::isInstance($object, 'Form');
     return parent::__construct($proto, $object);
 }
 /**
  * @return TextFileReceiver
  **/
 public function setQueue(MessageQueue $queue)
 {
     Assert::isInstance($queue, 'TextFileQueue');
     $this->queue = $queue;
     return $this;
 }
 /**
  * @param $uncacher UncacherGenericDAO same as self class
  * @return UncacherBase (this)
  */
 public function merge(UncacherBase $uncacher)
 {
     Assert::isInstance($uncacher, 'UncacherGenericDAO');
     return $this->mergeSelf($uncacher);
 }
Ejemplo n.º 23
0
 /**
  * @return Criteria
  **/
 public function dropProjectionByType($dropTypes)
 {
     Assert::isInstance($this->projection, 'ProjectionChain');
     $this->projection->dropByType($dropTypes);
     return $this;
 }
Ejemplo n.º 24
0
 /**
  * @return PrimitiveIdentifier
  **/
 public static function prototypedIdentifier($class, $name = null)
 {
     Assert::isInstance($class, 'DAOConnected');
     $dao = is_string($class) ? call_user_func(array($class, 'dao')) : $class->dao();
     return self::prototyped($class, $dao->getIdName(), $name);
 }
 /**
  * @return AMQPChannelInterface
  **/
 public function basicConsume($queue, $autoAck, AMQPConsumer $callback)
 {
     Assert::isInstance($callback, 'AMQPPeclQueueConsumer');
     try {
         $this->consumer = $callback->setQueueName($queue)->setAutoAcknowledge($autoAck === true);
         $obj = $this->lookupQueue($queue);
         $this->consumer->handleConsumeOk($this->consumer->getConsumerTag());
         /**
          * blocking function
          */
         $obj->consume(array($callback, 'handlePeclDelivery'), $autoAck ? AMQP_AUTOACK : self::AMQP_NONE);
     } catch (Exception $e) {
         $this->clearConnection();
         throw new AMQPServerException($e->getMessage(), $e->getCode(), $e);
     }
     return $this;
 }
 /**
  * @return GoogleChartLineStyle
  **/
 public function addStyle($style)
 {
     Assert::isInstance($style, 'ChartLabelStyle');
     return parent::addStyle($style);
 }
 /**
  * @param $uncacher UncacherCacheDaoWorkerLists same as self class
  * @return BaseUncacher (this)
  */
 public function merge(UncacherBase $uncacher)
 {
     Assert::isInstance($uncacher, get_class($this));
     return $this->mergeSelf($uncacher);
 }
 /**
  * @param $uncacher UncacherNullDaoWorker same as self class
  * @return BaseUncacher (this)
  */
 public function merge(UncacherBase $uncacher)
 {
     Assert::isInstance($uncacher, 'UncacherNullDaoWorker');
     return $this;
 }
 protected function call($method, DTOMessage $request, $resultClass)
 {
     $requestDto = $request->makeDto();
     Assert::isInstance($requestDto, 'DTOClass');
     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') {
                 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');
         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');
         Assert::isEqual(get_class($result), $resultClass);
         Assert::isTrue($result->entityProto()->validate($result, $form), Assert::dumpArgument($result));
     }
     return $result;
 }
 /**
  * @return DaoSynchronizer
  **/
 public function setSlave(GenericDAO $slave)
 {
     Assert::isInstance($slave, 'ProtoDAO');
     return parent::setSlave($slave);
 }