本文整理汇总了PHP中Scalr::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr::getContainer方法的具体用法?PHP Scalr::getContainer怎么用?PHP Scalr::getContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr
的用法示例。
在下文中一共展示了Scalr::getContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*/
function __construct()
{
$this->Logger = \Scalr::getContainer()->logger('SignalHandler');
if (!function_exists("pcntl_signal")) {
throw new \Exception("Function pcntl_signal() is not found. PCNTL must be enabled in PHP.", E_ERROR);
}
}
示例2: run
public function run()
{
$container = \Scalr::getContainer();
$db = $container->adodb;
$row = $db->GetRow("SHOW TABLES LIKE 'upgrades'");
if ($row) {
print "Tables already exist. Terminating.\n";
exit;
}
$script = <<<EOL
CREATE TABLE `upgrades` (
`uuid` VARBINARY(16) NOT NULL COMMENT 'Unique identifier of update',
`released` DATETIME NOT NULL COMMENT 'The time when upgrade script is issued',
`appears` DATETIME NOT NULL COMMENT 'The time when upgrade does appear',
`applied` DATETIME DEFAULT NULL COMMENT 'The time when update is successfully applied',
`status` TINYINT NOT NULL COMMENT 'Upgrade status',
`hash` VARBINARY (20) COMMENT 'SHA1 hash of the upgrade file',
PRIMARY KEY (`uuid`),
INDEX `idx_status` (`status`),
INDEX `idx_appears` (`appears`)
) ENGINE = InnoDB;
CREATE TABLE `upgrade_messages` (
`uuid` VARBINARY(16) NOT NULL COMMENT 'upgrades.uuid reference',
`created` DATETIME NOT NULL COMMENT 'Creation timestamp',
`message` TEXT COMMENT 'Error messages',
INDEX idx_uuid (`uuid`),
CONSTRAINT `upgrade_messages_ibfk_1` FOREIGN KEY (`uuid`) REFERENCES `upgrades` (`uuid`) ON DELETE CASCADE
) ENGINE = InnoDB;
EOL;
$lines = array_filter(preg_split('/;[\\s\\r\\n]*/m', $script));
foreach ($lines as $stmt) {
$db->Execute($stmt);
}
}
示例3: OnBeforeInstanceLaunch
/**
* {@inheritdoc}
* @see \Scalr\Observer\AbstractEventObserver::OnBeforeInstanceLaunch()
*/
public function OnBeforeInstanceLaunch(\BeforeInstanceLaunchEvent $event)
{
if ($event->DBServer->platform != \SERVER_PLATFORMS::EC2) {
return;
}
$DBFarm = $event->DBServer->GetFarmObject();
$DBFarmRole = $event->DBServer->GetFarmRoleObject();
// Create EBS volume for MySQLEBS
if (!$event->DBServer->IsSupported("0.6")) {
// Only for old AMIs
if ($DBFarmRole->GetRoleObject()->hasBehavior(\ROLE_BEHAVIORS::MYSQL) && $DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_DATA_STORAGE_ENGINE) == \MYSQL_STORAGE_ENGINE::EBS) {
$server = $event->DBServer;
$masterServer = $DBFarm->GetMySQLInstances(true);
$isMaster = !$masterServer || $masterServer[0]->serverId == $server->serverId;
$farmMasterVolId = $DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_MASTER_EBS_VOLUME_ID);
$createEbs = $isMaster && !$farmMasterVolId;
if ($createEbs) {
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new FarmLogMessage($event->DBServer, sprintf("Need EBS volume for MySQL %s instance...", $isMaster ? "Master" : "Slave")));
$req = new CreateVolumeRequestData($event->DBServer->GetProperty(\EC2_SERVER_PROPERTIES::AVAIL_ZONE), $DBFarmRole->GetSetting(Entity\FarmRoleSetting::MYSQL_EBS_VOLUME_SIZE));
$aws = $event->DBServer->GetEnvironmentObject()->aws($DBFarmRole->CloudLocation);
$res = $aws->ec2->volume->create($req);
if (!empty($res->volumeId)) {
$DBFarmRole->SetSetting(Entity\FarmRoleSetting::MYSQL_MASTER_EBS_VOLUME_ID, $res->volumeId, Entity\FarmRoleSetting::TYPE_LCL);
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new FarmLogMessage($event->DBServer, sprintf("MySQL %S volume created. Volume ID: %s...", $isMaster ? "Master" : "Slave", !empty($res->volumeId) ? $res->volumeId : null)));
}
}
}
}
}
示例4: xRequestResultAction
public function xRequestResultAction()
{
$this->request->defineParams(array('requests' => array('type' => 'json'), 'decision'));
if (!in_array($this->getParam('decision'), array(FarmLease::STATUS_APPROVE, FarmLease::STATUS_DECLINE))) {
throw new Scalr_Exception_Core('Wrong status');
}
foreach ($this->getParam('requests') as $id) {
$req = $this->db->GetRow('SELECT * FROM farm_lease_requests WHERE id = ? LIMIT 1', array($id));
if ($req) {
$dbFarm = DBFarm::LoadByID($req['farm_id']);
$this->user->getPermissions()->validate($dbFarm);
$this->db->Execute('UPDATE farm_lease_requests SET status = ?, answer_comment = ?, answer_user_id = ? WHERE id = ?', array($this->getParam('decision'), $this->getParam('comment'), $this->user->getId(), $id));
try {
$mailer = Scalr::getContainer()->mailer;
if ($dbFarm->ownerId) {
$user = Entity\Account\User::findPk($dbFarm->ownerId);
if (\Scalr::config('scalr.auth_mode') == 'ldap') {
$email = $user->getSetting(Entity\Account\User\UserSetting::NAME_LDAP_EMAIL);
if (!$email) {
$email = $user->email;
}
} else {
$email = $user->email;
}
$mailer->addTo($email);
} else {
$mailer = null;
}
} catch (Exception $e) {
$mailer = null;
}
if ($this->getParam('decision') == FarmLease::STATUS_APPROVE) {
if ($req['request_days'] > 0) {
$dt = $dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE);
$dt = new DateTime($dt);
$dt->add(new DateInterval('P' . $req['request_days'] . 'D'));
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND, null);
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_approve.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{date}}' => $dt->format('M j, Y'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
} else {
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_STATUS, '');
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE, '');
$dbFarm->SetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND, '');
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_forever.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
}
} else {
$dt = new DateTime($dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE));
SettingEntity::increase(SettingEntity::LEASE_DECLINED_REQUEST);
if ($mailer) {
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_decline.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{date}}' => $dt->format('M j, Y'), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
}
}
}
}
$this->response->success();
}
示例5: setUserRoles
/**
* Saves all relations between all users of this team and ACL roles
*
* @param array $data Roles array should look like array(user_id => array(account_role_id, ...))
* @throws \Scalr\Acl\Exception\AclException
*/
public function setUserRoles(array $data = array())
{
if (empty($this->id)) {
throw new \Scalr\Acl\Exception\AclException(sprintf("ID of the team is expected. It hasn't been initialized yet."));
}
\Scalr::getContainer()->acl->setAllRolesForTeam($this->id, $data, $this->accountId);
}
示例6: toPhp
/**
* {@inheritdoc}
* @see \Scalr\Model\Type\AbstractType::toPhp()
*/
public function toPhp($value)
{
if ($value === null) {
return null;
}
return \Scalr::getContainer()->crypto->decrypt($value);
}
示例7: setUp
/**
* {@inheritdoc}
* @see \Scalr\Tests\TestCase::setUp()
*/
protected function setUp()
{
$this->config = \Scalr::getContainer()->config;
if (!$this->config->defined('scalr.crontab')) {
$this->markTestSkipped("scalr.crontab section of config has not been defined.");
}
}
示例8: __construct
/**
* @param $config
* @key string $jobDir
* @key string $clsSuffix
* @key string $clsNamespace
* @key bool $oldSyntax (default true)
* TODO: add $getopt key
* TODO: support new syntax: php cron.php [options] task
*/
function __construct($config)
{
foreach ($config as $k => $v) {
$this->{$k} = $v;
}
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
}
示例9: __construct
/**
* @param $config
* @key string [name]
* @key string [key]
* @key array [items]
*/
function __construct($config)
{
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
$this->initialConfig = $config;
$this->shm = new Scalr_System_Ipc_Shm($config);
$key = $this->shm->key + 8;
$this->logger->debug(sprintf("Get semaphore (key: 0x%08x)", $key));
$this->sem = sem_get($key, 1, 0666, true);
if (!$this->sem) {
throw new Scalr_System_Ipc_Exception("Cannot sem_get (key: {$key})");
}
if (!sem_acquire($this->sem)) {
throw new Scalr_System_Ipc_Exception("Cannot acquire semaphore");
}
try {
$meta = $this->getMeta();
if ($meta === null) {
$this->clear0();
}
sem_release($this->sem);
} catch (Exception $e) {
sem_release($this->sem);
throw $e;
}
if ($config["items"]) {
foreach ($config["items"] as $item) {
$this->add($item);
}
}
}
示例10: Run
public function Run()
{
$container = Scalr::getContainer();
$db = $container->adodb;
$db->Execute("ALTER TABLE `farm_role_scripts` ADD `script_path` VARCHAR( 255 ) NULL ;");
$db->Execute("ALTER TABLE `apache_vhosts` DROP INDEX `ix_name` , ADD UNIQUE `ix_name` ( `name` , `env_id` , `farm_id` ) ;");
}
示例11: sendRequest
/**
* Makes request itself to the set or default url
*
* @name sendRequest
* @param mixed $url
* @return array $data
*/
private function sendRequest()
{
try {
$response = \Scalr::getContainer()->http->sendRequest($this->httpRequest);
$data = $response->getBody()->toString();
$this->LastResponseHeaders = $response->getHeaders();
$this->LastResponseBody = $data;
if ($response->getResponseCode() >= 400) {
$errMsg = json_decode($data);
if (is_object($errMsg)) {
$errMsg = @array_values(@get_object_vars($errMsg));
$errMsg = $errMsg[0];
}
$code = $errMsg->code ? $errMsg->code : 0;
$msg = $errMsg->details ? $errMsg->details : trim($data);
throw new Exception(sprintf('Request to Rackspace failed (Code: %s): %s', $code, $msg));
}
} catch (Exception $e) {
if ($e->innerException) {
$message = $e->innerException->getMessage();
} else {
$message = $e->getMessage();
}
throw new Exception($message);
}
return $data;
}
示例12: __construct
function __construct($nodeName, $jobConfig)
{
parent::__construct($nodeName, $jobConfig);
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
if (!key_exists("datacenter", $jobConfig)) {
throw new Scalr_System_Cronjob_Exception("Configuration array must have a key for 'datacenter'");
}
$dcConfig = $jobConfig["datacenter"];
if (!$dcConfig["centers"]) {
throw new Scalr_System_Cronjob_Exception("No datacenters defined in configuration");
}
if (!$dcConfig["leader"]) {
throw new Scalr_System_Cronjob_Exception("Configuration array must have a key for 'datacenter'.'leader' " . "that names the leader datacenter");
}
$centers = array_map("trim", explode(",", $dcConfig["centers"]));
$nodeCenterMap = array();
foreach ($centers as $center) {
$nodes = array_map("trim", explode(",", $dcConfig[$center]));
foreach ($nodes as $node) {
$nodeCenterMap[$node] = $center;
}
}
$this->dataCenter = key_exists($this->nodeName, $nodeCenterMap) ? $nodeCenterMap[$this->nodeName] : $dcConfig["default"];
$this->leaderDataCenter = $dcConfig["leader"];
}
示例13: run1
protected function run1($stage)
{
$this->console->out(sprintf("Reencrypting %s database from %s/%s to %s/%s!", \Scalr::getContainer()->config->get('scalr.connections.mysql.name'), $this->source->getCryptoAlgo(), $this->source->getCipherMode(), $this->target->getCryptoAlgo(), $this->target->getCipherMode()));
set_error_handler(function ($code, $message, $file, $line, $context) {
\Scalr::errorHandler($code, $message, $file, $line, $context);
if ($code == E_STRICT) {
throw new Exception($message);
}
}, E_USER_ERROR | E_STRICT | E_RECOVERABLE_ERROR | E_ERROR);
try {
$this->db->Execute('START TRANSACTION;');
$this->recrypt('ssh_keys', ['private_key', 'public_key']);
$this->recrypt('services_ssl_certs', ['ssl_pkey', 'ssl_pkey_password']);
$this->recrypt('account_user_settings', ['value'], "WHERE `name` = 'security.2fa.ggl.key'", ['user_id', 'name']);
$this->recrypt('services_chef_servers', ['auth_key', 'v_auth_key']);
$this->recrypt('variables', ['value'], '', ['name'], $this->globals);
$this->recrypt('account_variables', ['value'], '', ['name', 'account_id'], $this->globals);
$this->recrypt('client_environment_variables', ['value'], '', ['name', 'env_id'], $this->globals);
$this->recrypt('role_variables', ['value'], '', ['name', 'role_id'], $this->globals);
$this->recrypt('farm_variables', ['value'], '', ['name', 'farm_id'], $this->globals);
$this->recrypt('farm_role_variables', ['value'], '', ['name', 'farm_role_id'], $this->globals);
$this->recrypt('server_variables', ['value'], '', ['name', 'server_id'], $this->globals);
$reflection = new ReflectionClass('Scalr_Environment');
$method = $reflection->getMethod('getEncryptedVariables');
$method->setAccessible(true);
$this->recrypt('client_environment_properties', ['value'], "WHERE `name` IN ('" . implode("','", array_keys($method->invoke(null))) . "')");
$this->db->Execute("COMMIT;");
} catch (\Exception $e) {
$this->rollback($e->getCode(), $e->getMessage());
restore_error_handler();
throw $e;
}
restore_error_handler();
}
示例14: __construct
public function __construct($id = null)
{
$this->id = $id;
$this->container = \Scalr::getContainer();
$this->db = \Scalr::getDb();
$this->dbMessageKeyNotFound = get_class($this) . " " . $this->dbMessageKeyNotFound;
}
示例15: __construct
public function __construct(Scalr_Net_Dns_Bind_Transports_Ssh2_AuthInfo $authInfo, $host, $port, $rndcPath, $zonesPath)
{
$this->ssh2Client = new Scalr_Net_Ssh2_Client();
$this->logger = \Scalr::getContainer()->logger(__CLASS__);
$this->rndcPath = $rndcPath;
$this->zonesPath = $zonesPath;
$this->host = $host;
switch ($authInfo->getType()) {
case Scalr_Net_Dns_Bind_Transports_Ssh2_AuthInfo::TYPE_PASSWORD:
$this->ssh2Client->addPassword($authInfo->login, $authInfo->password);
break;
case Scalr_Net_Dns_Bind_Transports_Ssh2_AuthInfo::TYPE_PUBKEY:
$this->ssh2Client->addPubkey($authInfo->login, $authInfo->pubKeyPath, $authInfo->privKeyPath, $authInfo->keyPassword);
break;
}
try {
$this->ssh2Client->connect($host, $port);
} catch (Scalr_Net_Ssh2_Exception $e) {
throw new Exception("Unable to initialize SSH2 Transport: {$e->getMessage()}");
}
// COunt initial number of zones
$this->zonesCount = $this->rndcStatus();
if (!$this->zonesCount) {
throw new Exception(sprintf(_("Cannot fetch RNDC status on %s"), $host));
}
}