Exemple #1
0
 /**
  * @internal
  * @param Scope $scope
  * @param       $data
  * @return array|bool
  * @throws \Exception
  */
 public function getEmbededModels(Scope $scope, $data)
 {
     $embeddedData = array();
     $embeddedDataCount = 0;
     $defaultEmbeds = array();
     if ($this->defaultEmbeds) {
         $scope->addDefaultEmbeds($this->defaultEmbeds);
         // clean multi level embeds to keep only the 1st child
         $defaultEmbeds = array_map(function ($embed) {
             $embedKeys = explode('.', $embed, 2);
             return $embedKeys[0];
         }, $this->defaultEmbeds);
     }
     $embeds = array_unique(array_merge($defaultEmbeds, $this->availableEmbeds));
     foreach ($embeds as $potentialEmbed) {
         // Check if an available embed is requested
         if (!$scope->isRequested($potentialEmbed)) {
             continue;
         }
         if (!($resource = $this->callGetMethod($potentialEmbed, $data, $embeddedData))) {
             continue;
         }
         $embeddedData[$potentialEmbed] = $scope->getComposedChildScope($potentialEmbed, $resource)->getComposite();
         ++$embeddedDataCount;
     }
     return $embeddedDataCount === 0 ? false : $embeddedData;
 }
Exemple #2
0
 /**
  * Resolves the value of this definition, according to the current scope.
  *
  * This method is for internal use by the Container.
  *
  * @param Container $container
  *
  * @return mixed
  */
 public function get(Container $container)
 {
     if ($this->scope === null) {
         $this->scope = $this->getDefaultScope();
     }
     return $this->scope->get($this, $container);
 }
Exemple #3
0
 /**
  * @internal param $ScopeInterface ... $scope
  * @internal param callable $closure
  * @deprecated
  * @return mixed
  */
 public static function scope()
 {
     $scopes = func_get_args();
     $callable = array_pop($scopes);
     $scope = new Scope($scopes);
     return $scope->call($callable);
 }
Exemple #4
0
 protected function changeState($state)
 {
     $callbacks = $this->scope->getCallbacks($state);
     foreach ($callbacks as $callback) {
         $this->executeCallback($callback);
     }
 }
 public function testNullScope()
 {
     $s = new Scope(null);
     $this->assertFalse($s->hasScope(new Scope("foo")));
     $this->assertTrue($s->hasScope(new Scope(array())));
     $this->assertTrue($s->hasScope(new Scope()));
     $this->assertTrue($s->hasScope(new Scope(array())));
 }
 public function addScopeGroup($group)
 {
     $scope = new Scope();
     $scope->setBuilder($this->builder);
     foreach ($group as $p) {
         $scope->addOperation($p);
     }
     $this->scopeGroups[] = $scope;
 }
Exemple #7
0
 public function hasScope(Scope $scope)
 {
     foreach ($scope->getScopeAsArray() as $s) {
         if (!in_array($s, $this->scope)) {
             return false;
         }
     }
     return true;
 }
Exemple #8
0
 /**
  * Compose a Resource
  *
  * @param Resource $resource
  * @param string|null $scopeIdentifier
  * @param Scope|null $parentScopeInstance
  *
  * @return Scope
  */
 public function compose(Resource $resource, $scopeIdentifier = null, Scope $parentScopeInstance = null)
 {
     $scopeInstance = new Scope($this, $resource, $scopeIdentifier);
     // Update scope history
     if ($parentScopeInstance !== null) {
         // This will be the new children list of parents (parents parents, plus the parent)
         $scopeArray = $parentScopeInstance->getParentScopes();
         $scopeArray[] = $parentScopeInstance->getCurrentScope();
         $scopeInstance->setParentScopes($scopeArray);
     }
     return $scopeInstance;
 }
 public function getCurrentRequestOutput()
 {
     if (empty($this->path)) {
         \Redirect::withoutMessage(\Scope::url("home"));
     }
     $this->variables["path"] = $this->getApplicationVariableValue("path");
     $this->variables["siteTitle"] = \Scope::$domain->site_name;
     $this->getToolbar()->getNav()->getContent()->getLayout();
     if (empty(trim($this->variables['content'])) && !empty($this->current['children'])) {
         \Redirect::withoutMessage($this->current['children'][0]['href']);
     }
     $this->active[2] = $this->_findActiveNavItemAtLevel($this->nav, 2);
     if (@$this->active[2]["data"]["meta"]->sidebar == true) {
         $this->variables["sidebar"] = $this->_buildSidebar($this->active[2]);
     }
     if (!file_exists($this->current["file"])) {
         if (!empty($this->current["children"])) {
             \Redirect::withoutMessage(Scope::url($this->current["children"][0]["href"]));
         } else {
             \EventTower::fire("app.render.getAlternativeContent", ["app" => &$this, "reason" => ["status" => 404, "message" => "Content not Found"]]);
         }
     } else {
         $this->page()->body["content"] = (string) $this;
     }
     return $this;
 }
 /**
  * Pretty print with indentation.
  *
  * @param $indentLevel
  * @param int $spacesPerIndent
  * @return string
  */
 public function prettyPrint($indentLevel, $spacesPerIndent = 4)
 {
     $indent = str_repeat(str_repeat(' ', $spacesPerIndent), $indentLevel);
     $resultString = $indent . $this->name;
     if (!is_null($this->value)) {
         $resultString .= " " . $this->value;
     }
     if (is_null($this->getChildScope())) {
         $resultString .= ";";
     } else {
         $resultString .= " {";
     }
     if (false === $this->hasComment()) {
         $resultString .= "\n";
     } else {
         if (false === $this->getComment()->isMultiline()) {
             $resultString .= " " . $this->comment->prettyPrint(0, 0);
         } else {
             $comment = $this->getComment()->prettyPrint($indentLevel, $spacesPerIndent);
             $resultString = $comment . $resultString;
         }
     }
     if (!is_null($this->getChildScope())) {
         $resultString .= "" . $this->childScope->prettyPrint($indentLevel, $spacesPerIndent) . $indent . "}\n";
     }
     return $resultString;
 }
Exemple #11
0
 /**
  * When the api call results in RestException this method
  * will be called to return the error message
  *
  * @param RestException $exception exception that has reasons for failure
  *
  * @return array
  */
 public function message(RestException $exception)
 {
     //TODO: check Defaults::language and change result accordingly
     $r = array('error' => array('code' => $exception->getCode(), 'message' => $exception->getErrorMessage()) + $exception->getDetails());
     if (!Scope::get('Restler')->getProductionMode() && self::$includeDebugInfo) {
         $r += array('debug' => array('source' => $exception->getSource(), 'stages' => $exception->getStages()));
     }
     return $r;
 }
Exemple #12
0
 /**
  * Returns data visible from current scope.
  *
  * @param string $key
  * @param mixed  $default
  *
  * @return mixed
  */
 public function get($key, $default = null)
 {
     if (array_key_exists($key, $this->data)) {
         return $this->data[$key];
     }
     if (null === $this->parent) {
         return $default;
     }
     return $this->parent->get($key, $default);
 }
 public function __construct(array $params, $mainEntity)
 {
     $this->at = RestUrlParams::parseTimestamp(RestUrlParams::extractValue($params, RestUrlParams::AT));
     if ($this->at == RestUrlParams::ALL_TIMES) {
         $this->at = self::ALL_TIMES;
     }
     $this->published = RestUrlParams::parseBoolean(RestUrlParams::extractValue($params, RestUrlParams::PUBLISHED));
     $this->queryParamsMap = array();
     $this->scopeMap = array();
     if ($mainEntity != NULL) {
         foreach ($params as $paramName => $paramValue) {
             // Parameters can be specified with or without entity-prefix, e.g. 'entity/property=value' or just
             // 'property=value'. Check if an entity-prefix is provided.
             $entityName = NULL;
             $propertyName = NULL;
             $paramNameParts = explode(RestUrlParams::ENTITY_SEPARATOR, $paramName);
             if (count($paramNameParts) == 1) {
                 // It's like 'property=value'.
                 $entityName = $mainEntity->getName();
                 $propertyName = $paramName;
             } else {
                 if (count($paramNameParts) == 2) {
                     // It's like 'entity/property=value'.
                     $entityName = $paramNameParts[0];
                     $propertyName = $paramNameParts[1];
                 } else {
                     throw new Exception("Illegal query parameter '{$paramName}'.");
                 }
             }
             // If it's a scope parameter...
             if (strcasecmp($propertyName, RestUrlParams::SCOPE) == 0) {
                 // ...then parse it.
                 $this->scopeMap[$entityName] = Scope::parseValue($paramValue);
             } else {
                 // ...else add the value to the map at the correct entity-entry.
                 if (!array_key_exists($entityName, $this->queryParamsMap)) {
                     $this->queryParamsMap[$entityName] = array();
                 }
                 // If $paramName is 'id'...
                 if (strcasecmp($propertyName, RestUrlParams::ID) == 0) {
                     // ...then check if this is allowed for the given entity...
                     if (!$mainEntity->isObjectEntity()) {
                         throw new Exception("Cannot fetch entity '" . $mainEntity->getName() . "' by id.");
                     }
                     // ...and apply the correct property name and value.
                     $propertyName = $mainEntity->getObjectIdColumnName();
                     $paramValue = explode(RestUrlParams::ID_SEPARATOR, $paramValue);
                 }
                 $this->queryParamsMap[$entityName][$propertyName] = $paramValue;
             }
         }
     }
 }
 function __construct(ObjectEntity $entity, $id, array $propertyValues, $modifyingAction, $scopeValue = NULL)
 {
     $this->entity = $entity;
     $this->id = $id;
     $this->propertyValues = $propertyValues;
     $this->modifyingAction = $modifyingAction;
     if ($scopeValue == NULL) {
         $scopeValue = self::DEFAULT_SCOPE;
     }
     $this->scope = Scope::parseValue($scopeValue);
     $this->relatedObjects = array();
     $this->key = $this->entity->getName() . "[{$this->id}]";
 }
 private static function init()
 {
     if (self::$NULL_SCOPE === NULL) {
         self::$NULL_SCOPE = new Scope();
         self::$DEFAULT_SCOPES = array();
         foreach (self::$DEFAULT_SCOPE_VALUES as $defaultUnitTag => $defaultValue) {
             if (strlen($defaultValue) > 0) {
                 self::$DEFAULT_SCOPES[$defaultUnitTag] = self::parseValue($defaultValue);
             } else {
                 self::$DEFAULT_SCOPES[$defaultUnitTag] = self::$NULL_SCOPE;
             }
         }
     }
 }
Exemple #16
0
 /**
  * Create new Scope from the configuration string.
  *
  * @param \RomanPitak\Nginx\Config\Text $configString
  * @return Scope
  * @throws Exception
  */
 public static function fromString(Text $configString)
 {
     $scope = new Scope();
     while (false === $configString->eof()) {
         if (true === $configString->isEmptyLine()) {
             $scope->addPrintable(EmptyLine::fromString($configString));
         }
         $char = $configString->getChar();
         if ('#' === $char) {
             $scope->addPrintable(Comment::fromString($configString));
             continue;
         }
         if ('a' <= $char && 'z' >= $char) {
             $scope->addDirective(Directive::fromString($configString));
             continue;
         }
         if ('}' === $configString->getChar()) {
             break;
         }
         $configString->inc();
     }
     return $scope;
 }
 public function fetchRelatedObjectIdsOfEntity(MySQLi $mySQLi, Entity $otherEntity)
 {
     $queryContext = new QueryContext(array(), NULL);
     $scope = Scope::parseValue(Scope::VALUE_C_REF . Scope::VALUE_A_REF . Scope::VALUE_O_REF);
     $fetchedObjectIds = array();
     if ($otherEntity->isObjectEntity()) {
         $fetchedObjectRefs = array();
         $this->fetchRelatedObjectRefsOfEntity($mySQLi, $otherEntity, $queryContext, $scope, $fetchedObjectRefs);
         foreach ($fetchedObjectRefs as $fetchedObjectRef) {
             $fetchedObjectIds[] = $fetchedObjectRef->id;
         }
     } else {
         $fetchedObjectIds[] = 0;
     }
     return $fetchedObjectIds;
 }
 private static function validate($name)
 {
     try {
         $url = URL::getInstance();
         if ($name == null) {
             if (Session::getInstance()->isStarted()) {
                 $url->setController(DEFAULT_SESSION_CONTROLLER);
                 $url->setAction(DEFAULT_SESSION_ACTION);
                 return DEFAULT_SESSION_CONTROLLER;
             } else {
                 $url->setController(DEFAULT_REQUEST_CONTROLLER);
                 $url->setAction(DEFAULT_REQUEST_ACTION);
                 return DEFAULT_REQUEST_CONTROLLER;
             }
         }
         $controller = $name . CONTROLLER;
         $class = new ReflectionClass($controller);
         if ($class->isAbstract()) {
             throw new LogicException();
         }
         $classScope = $class->getConstant('SCOPE');
         if ($class->implementsInterface('Context')) {
             if (Scope::isAcceptable($classScope)) {
                 return $name;
             }
             if ($classScope == Scope::SESSION) {
                 $url->setController(DEFAULT_REQUEST_CONTROLLER);
                 $url->setAction(DEFAULT_REQUEST_ACTION);
                 return DEFAULT_REQUEST_CONTROLLER;
             }
             if ($classScope == Scope::REQUEST) {
                 ControllerFactory::create(DEFAULT_APPLICATION_CONTROLLER)->redirectToError();
             }
         }
         return DEFAULT_APPLICATION_CONTROLLER;
     } catch (LogicException $e) {
         $e->getTraceAsString();
         ControllerFactory::create(DEFAULT_APPLICATION_CONTROLLER)->redirectToError();
     }
 }
Exemple #19
0
 public function testSuccess()
 {
     $onExit = 'untouched';
     $onFailure = 'untouched';
     $onSuccess = 'untouched';
     $scope = new Scope();
     $scope->onExit(function () use(&$onExit) {
         $onExit = 'touched';
     });
     $scope->onFailure(function () use(&$onFailure) {
         $onFailure = 'touched';
     });
     $scope->onSuccess(function () use(&$onSuccess) {
         $onSuccess = 'touched';
     });
     $this->assertEquals($onExit, 'untouched');
     $this->assertEquals($onFailure, 'untouched');
     $this->assertEquals($onSuccess, 'untouched');
     $scope->markSuccessful();
     unset($scope);
     $this->assertEquals($onExit, 'touched');
     $this->assertEquals($onFailure, 'untouched');
     $this->assertEquals($onSuccess, 'touched');
 }
Exemple #20
0
 public function __toString()
 {
     $server = Directive::create('server');
     $childScope = Scope::create();
     foreach ($this->directives as $key => $value) {
         $childScope->addDirective(Directive::create($key, $value));
     }
     $server->setChildScope($childScope);
     foreach ($this->locations as $url => $location) {
         if ($location === null || !$location instanceof Location) {
             throw new \RuntimeException(sprintf('expected %s but got %s', Location::class, gettype($location)));
         }
         $directive = Directive::create('location', $url);
         $locationChildScope = Scope::create();
         foreach ($location as $key => $value) {
             if (!is_array($value)) {
                 $locationChildScope->addDirective(Directive::create($key, $value));
                 continue;
             }
             foreach ($value as $item) {
                 $locationChildScope->addDirective(Directive::create($key, $item));
             }
         }
         $directive->setChildScope($locationChildScope);
         $childScope->addDirective($directive);
     }
     return (string) Scope::create()->addDirective($server);
 }
 public function establishLinks(Schema $schema, LinkEntity $linkEntity, $oneFkColumnName, $oneId, $otherFkColumnName, array $otherIds, Audit $audit)
 {
     // Get the id's of all existing links.
     $scope = Scope::parseValue(Scope::VALUE_P_ALL);
     $query = new QueryEntity($linkEntity, $this->defaultQueryContext, $scope);
     $query->addWhereClause($oneFkColumnName, $oneId);
     $mySQLi = $schema->getMySQLi();
     $queryString = $query->getQueryString();
     $queryResult = $mySQLi->query($queryString);
     if (!$queryResult) {
         throw new Exception("Error fetching '{$otherFkColumnName}' properties of link entity " . $linkEntity->getName() . "[{$oneId}] - {$mySQLi->error}\n<!--\n{$queryString}\n-->");
     }
     // Compose a list of otherIds that must be deleted and adjust $otherIds, so it will only contain links that
     // must be created.
     $surplusOtherIds = array();
     while ($dbObject = $queryResult->fetch_assoc()) {
         $existingOtherId = $dbObject[$otherFkColumnName];
         $key = array_search($existingOtherId, $otherIds);
         if ($key !== FALSE) {
             // The link is already there.
             unset($otherIds[$key]);
         } else {
             $surplusOtherIds[] = $existingOtherId;
         }
     }
     $queryResult->close();
     // Delete surplus links.
     if (count($surplusOtherIds) > 0) {
         $propertyValues = array();
         $propertyValues[$oneFkColumnName] = $oneId;
         $propertyValues[$otherFkColumnName] = $surplusOtherIds;
         $this->terminateLinks($schema, $linkEntity, $propertyValues, $audit);
     }
     // Create missing links.
     if (count($otherIds) > 0) {
         $propertyValues = array();
         $propertyValues[$oneFkColumnName] = $oneId;
         foreach ($otherIds as $otherId) {
             // Pass a NULL to indicate that a new link object must be inserted.
             $propertyValues[$otherFkColumnName] = $otherId;
             $this->insertOrUpdate($schema, $linkEntity, NULL, $propertyValues, $audit);
         }
     }
 }
Exemple #22
0
 public function testSerialize()
 {
     $s = new Scope(array("foo", "bar", "baz"));
     $t = new Scope($s->toArray());
     $this->assertTrue($t->equals($s));
 }
Exemple #23
0
 /**
  * Checks if the other task has equal scope
  *
  * @param Task $other Other task
  * @return bool
  */
 public function hasEqualScope(self $other)
 {
     return $this->scope->equals($other->scope);
 }
Exemple #24
0
 /**
  * Check that if if the selected scope for this SE is EGI, the parent site
  * is also EGI
  * @param Site $site The SE's parent site
  * @param Scope $scope The SE's new scope
  * @return null
  */
 private function scopeCheck(\Site $site, \Scope $scope)
 {
     // If the scope isn't EGI then don't raise an error
     if ($scope->getName() != 'EGI') {
         return;
     }
     if ($site->getScopes()->first()->getName() != "EGI") {
         throw new \Exception("For this service to be EGI scoped, {$site} must also be EGI scoped.");
     }
 }
Exemple #25
0
 /**
  * @depends testCallValuePassing
  */
 public function testCallDefaultValueIfNotExists()
 {
     $scope = new Scope();
     $scope->test = 3;
     $scope->call(function ($x = 5) {
         $this->assertEquals(5, $x);
     });
 }
Exemple #26
0
 /**
  *  Creates a new scope, setting the old one as its parent
  */
 public function new_scope()
 {
     $this->scopes[] = $scope = new Scope();
     $scope->setParent($this->scope);
     return $this->scope = $scope;
 }
Exemple #27
0
 /**
  * {@inheritdoc}
  *
  * @return callable
  */
 public function getDefinition()
 {
     return $this->scope->peridotBindTo($this->definition);
 }
 /**
  * Constructor
  *
  * @param   xp.compiler.ast.RoutineNode $routine
  */
 public function __construct($routine = null)
 {
     $this->routine = $routine;
     parent::__construct();
 }
		<?php 
        }
        ?>

	<?php 
    }
    ?>

	<?php 
}
?>

</div>

<a class="btn btn-success btn-block" href="<?php 
echo Scope::url("api/explorer");
?>
">

	<br />

	<?php 
echo UI_Icon::create("material", "code", "xxl");
?>

	<br />

	<span class="h4">Explore the API interactively</span>

	<br />
Exemple #30
0
 function IfEqScope(&$lexer, &$container)
 {
     $this->_END_TAG = 'end-if-eq';
     $this->condition_var = $lexer->current_tagparams[0];
     $this->raw = $lexer->current_tagparams[1];
     if ($this->raw[0] == '"') {
         if ($this->raw[strlen($this->raw) - 1] != '"') {
             fatal("Improperly formatted string in " . $lexer->tagtext);
         }
         $this->_value = str_replace(array('\\"', '\\\\'), array('"', '\\'), substr($this->raw, 1, strlen($this->raw) - 2));
         $this->rtype = 'literal';
     } else {
         switch ($this->raw) {
             case 'LOGGED_IN_USR_ID':
                 $this->_value = get_user_id();
                 $this->rtype = 'literal';
                 break;
             case 'LOGGED_IN_USR_NAME':
                 $this->_value = get_user_name();
                 $this->rtype = 'literal';
                 break;
             case 'LOGGED_IN_USR_USERNAME':
                 $this->_value = get_user_username();
                 $this->rtype = 'literal';
                 break;
             case 'CURRENT_TIME':
                 $this->_value = date('Y-m-d H:i:s');
                 $this->rtype = 'literal';
                 break;
             default:
                 $this->rtype = 'field';
         }
     }
     parent::Scope($lexer, $container);
 }