示例#1
0
 /**
  * Create a new command instance.
  *
  * @param int         $ownerId   The id of the entity
  * @param int         $ownerType The type of owner (implied from entity type if null)
  * @param string|null $tag       Optional string to describe your job
  */
 public function __construct($ownerId, $ownerType, $tag = null)
 {
     parent::__construct($tag);
     //  Make sure we have a good types
     $this->ownerInfo = OwnerTypes::getOwner($ownerId, $ownerType);
     $this->ownerId = $ownerId;
     $this->ownerType = is_numeric($ownerType) && OwnerTypes::contains($ownerType) ? $ownerType : OwnerTypes::defines($ownerType, true);
 }
示例#2
0
 /**
  * @param int        $ownerId
  * @param int|string $ownerType String types will be converted to numeric equivalent
  *
  * @return EnterpriseModel|Cluster|User|Instance|Server|\stdClass
  */
 public static function getOwner($ownerId, &$ownerType)
 {
     $_message = 'The owner id "' . $ownerType . ':' . $ownerId . '" could not be found.';
     if (!is_numeric($ownerType)) {
         try {
             $ownerType = OwnerTypes::defines(strtoupper($ownerType), true);
         } catch (\InvalidArgumentException $_ex) {
             //  Force a FAIL
             $ownerId = $ownerType = -1;
         }
     }
     //  Owner types >= 1000 are reserved for logical, non-physical, entities such as the console or dashboard
     if ($ownerType >= static::CONSOLE) {
         $_owner = new \stdClass();
         $_owner->id = $ownerId;
         $_owner->type = $ownerType;
         return $_owner;
     }
     //  And the rest have models
     //  @todo make more dynamic so new constants don't require new lookup switch cases
     switch ($ownerType) {
         case static::USER:
             return static::_lookupUser($ownerId);
         case static::SERVICE_USER:
             return static::_lookupServiceUser($ownerId);
         case static::MOUNT:
             return static::_lookupMount($ownerId);
         case static::INSTANCE:
             return static::_lookupInstance($ownerId);
         case static::SERVER:
             return static::_lookupServer($ownerId);
         case static::CLUSTER:
             return static::_lookupCluster($ownerId);
     }
     throw new ModelNotFoundException($_message);
 }
示例#3
0
 /**
  * @param string $entityType Given an entity type, return the associated owner type
  *
  * @return bool
  */
 public static function mapOwnerType($entityType)
 {
     return OwnerTypes::defines(strtoupper(trim($entityType)), true);
 }