Scalr\Stats\CostAnalytics\Events\AbstractEvent::__construct PHP Method

__construct() public method

Constructor
public __construct ( )
    public function __construct()
    {
        $this->timelineEvent = new TimelineEventEntity();
        $request = \Scalr::getContainer()->request;
        $this->user = $request instanceof Scalr_UI_Request ? $request->getUser() : null;
        $this->timelineEvent->userId = $this->user->id;
        if ($request instanceof Scalr_UI_Request && $request->getEnvironment() instanceof Scalr_Environment) {
            $this->environment = $request->getEnvironment();
            $this->timelineEvent->envId = $this->environment->id;
            $this->timelineEvent->accountId = $this->environment->clientId;
        }
        $constName = 'Scalr\\Stats\\CostAnalytics\\Entity\\TimelineEventEntity::EVENT_TYPE_' . strtoupper(substr(\Scalr::decamelize(preg_replace('/^.+\\\\([\\w]+)$/', '\\1', get_class($this))), 0, -6));
        if (!defined($constName)) {
            throw new AnalyticsException(sprintf("Constant '%s' is not defined.", $constName));
        }
        $this->timelineEvent->eventType = constant($constName);
    }

Usage Example

示例#1
0
 /**
  * Constructor
  *
  * @param   \Scalr_Environment  $env           The environment
  * @param   string              $ccId          The identifier of the cost center which is assigned
  * @param   string              $oldCcId       The identifier of the old cost center which is replaced
  */
 public function __construct(Scalr_Environment $env, $ccId, $oldCcId)
 {
     parent::__construct();
     array_push($this->ccs, $ccId, $oldCcId);
     $ccName = AccountTagEntity::fetchName($ccId, TagEntity::TAG_ID_COST_CENTRE);
     $oldCcName = AccountTagEntity::fetchName($oldCcId, TagEntity::TAG_ID_COST_CENTRE);
     $this->message = sprintf("User %s replaced cost center '%s' with '%s' in the enviroment '%s' id:%d", strip_tags($this->getUserEmail()), strip_tags($oldCcName), strip_tags($ccName), strip_tags($env->name), $env->id);
     $this->messageToHash = sprintf('%s|%s|%s|%s|%s', $this->timelineEvent->dtime->format('Y-m-d'), $oldCcId, $ccId, $env->id, $this->getUserEmail());
 }
All Usage Examples Of Scalr\Stats\CostAnalytics\Events\AbstractEvent::__construct