Decamelizes a string
public static decamelize ( string $str ) : string | ||
$str | string | A string |
return | string | Returns decamelized string |
/** * Constructor * * @throws \Scalr\Exception\AnalyticsException */ 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; $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); }
/** * Constructor */ public function __construct() { $basename = preg_replace('/^.+\\\\(\\w+)$/', '$1', get_class($this)); $this->name = \Scalr::decamelize($basename); $this->pids = []; $this->toDisconnect = []; $this->setLogger(\Scalr::getContainer()->logger($this->name)->setLevel($this->config()->log_level)); //It is possible to redefine default payload class for the task if (file_exists(__DIR__ . '/Payload/' . $basename . 'Payload.php')) { $this->payloadClass = __NAMESPACE__ . '\\Payload\\' . $basename . 'Payload'; } }
/** * Constructor */ public function __construct() { $basename = preg_replace('/^.+\\\\(\\w+)$/', '$1', get_class($this)); $this->name = \Scalr::decamelize($basename); $this->pids = []; $this->toDisconnect = []; $this->setLogger(\Scalr::getContainer()->logger($this->name)->setLevel($this->config()->log_level)); //It is possible to redefine default payload class for the task if (file_exists(__DIR__ . '/Payload/' . $basename . 'Payload.php')) { $this->payloadClass = __NAMESPACE__ . '\\Payload\\' . $basename . 'Payload'; } $container = \Scalr::getContainer(); $container->release('auditlogger'); $container->setShared('auditlogger', function ($cont) { return new AuditLogger(null, null, null, null, AuditLogger::REQUEST_TYPE_SYSTEM, $this->getName()); }); }
/** * Gets a list of servers by filter * * @param array $filter optional Filter value ['envId' => 'value'] * @return array Returns array of DBServer objects */ public static function listByFilter(array $filter = null) { $result = []; $db = \Scalr::getDb(); $where = "WHERE 1=1"; if (isset($filter)) { foreach ($filter as $name => $value) { $fieldName = \Scalr::decamelize($name); $where .= " AND " . $fieldName . "=" . $db->qstr($value); } } $servers = $db->GetAll("SELECT * FROM servers " . $where); foreach ($servers as $server) { $DBServer = new DBServer($server['server_id']); foreach (self::$FieldPropertyMap as $k => $v) { if (isset($server[$k])) { $DBServer->{$v} = $server[$k]; } } $result[] = $DBServer; } return $result; }
/** * Saves an entity to database * * @return \Scalr\Server\History * @throws Exception */ public function save() { $stmt = array(); $bind = array(); $idKey = 'id'; $idValue = array(); $cols = array(); foreach ($this->_getFields() as $field) { $cols[$field] = $this->{$field}; } if (array_key_exists($idKey, $cols)) { if ($cols[$idKey]) { $idValue[] = $cols[$idKey]; } unset($cols[$idKey]); } foreach ($cols as $field => $value) { $stmt[] = "`" . \Scalr::decamelize($field) . "` = ?"; $bind[] = $value; } try { $stmt = (empty($idValue) ? "INSERT" : "UPDATE") . " `servers_history` SET " . join(", ", $stmt) . (!empty($idValue) ? " WHERE `" . \Scalr::decamelize($idKey) . "` = ?" : ""); $this->db->Execute($stmt, array_merge($bind, $idValue)); if (empty($idValue)) { $this->{$idKey} = $this->db->Insert_ID(); } } catch (Exception $e) { throw new Exception(sprintf("Cannot save server history record. Error: %s", $e->getMessage()), $e->getCode()); } return $this; }
/** * Loads field or class annotation * * @param \ReflectionProperty|\ReflectionClass $refl Reflection property or class */ public function load($refl) { if ($refl instanceof \ReflectionProperty || $refl instanceof \ReflectionClass) { $str = join('|', array_map('preg_quote', array_keys($this->mappingClasses))); $comment = $refl->getDocComment(); $annotation = $refl instanceof \ReflectionProperty ? new Field() : new Entity(); $annotation->name = $refl->name; if (preg_match_all('/^\\s+\\*\\s+@(' . $str . ')(.*)$/m', $comment, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $mappingClass = 'Scalr\\Model\\Mapping\\' . $m[1]; $annotationProperty = lcfirst($m[1]); $mapping = new $mappingClass(); if (!empty($m[2])) { $definition = trim($m[2], "\r\t\n ()"); if ($definition) { if (method_exists($mapping, '__invoke')) { $mapping(trim($definition, "\"'")); } else { $str = '{' . preg_replace('/([\\w"]+)\\s*=/', '"$1":', $definition) . '}'; $type = json_decode($str, true); if ($type) { foreach (get_class_vars($mappingClass) as $k => $defaultValue) { if (isset($type[$k])) { $mapping->{$k} = $type[$k]; } } } else { throw new ModelException(sprintf("Invalid annotation '%s' for %s of %s", $m[0], $refl->name, isset($refl->class) ? $refl->class : 'class')); } } } } $annotation->{$annotationProperty} = $mapping; } } if ($refl instanceof \ReflectionProperty) { if (!$annotation->column instanceof Column) { $annotation->column = new Column(); $annotation->column->type = 'string'; } if (!$annotation->column->name) { $annotation->column->name = \Scalr::decamelize($annotation->name); } } $refl->annotation = $annotation; } else { throw new \InvalidArgumentException(sprintf('Either ReflectionProperty or ReflectionClass is expected, "%s" passed.', is_object($refl) ? get_class($refl) : gettype($refl))); } }
/** * Checks if user has permissions to project in environment or account scope * * @param string $projectId Identifier of the project * @param array $criteria ['envId' => '', 'clientid' => ''] * @return bool|mixed */ public function checkPermission($projectId, array $criteria) { $and = ''; foreach ($criteria as $name => $value) { $field = 'f.' . \Scalr::decamelize($name); $and .= " AND " . $field . "=" . $this->db->escape($value); } $projectEntity = new ProjectEntity(); $projectId = $projectEntity->type('projectId')->toDb($projectId); $where = " WHERE p.project_id = UNHEX('" . $projectId . "') AND EXISTS (\n SELECT * FROM farms f\n LEFT JOIN farm_settings fs ON f.id = fs.farmid\n WHERE fs.name = '" . Entity\FarmSetting::PROJECT_ID . "'\n AND REPLACE(fs.value, '-', '') = HEX(p.project_id)\n {$and})"; $sql = "SELECT " . $projectEntity->fields('p') . "\n FROM " . $projectEntity->table('p') . $where; return $this->db->GetOne($sql); }