コード例 #1
0
 /**
  * Test Resource::operationAllowed().
  */
 public function testGetLink()
 {
     $this->assertNotEmpty($this->resource->getLink('self'));
     $this->assertNotEmpty($this->resource->getLink('#operate'));
     $this->setExpectedException('\\InvalidArgumentException');
     $this->resource->getLink('nonexistent');
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function getLink($rel, $absolute = false)
 {
     if ($rel === '#edit') {
         return $this->getUri($absolute);
     }
     return parent::getLink($rel, $absolute);
 }
コード例 #3
0
 /**
  * Delete the environment.
  *
  * @param bool $deactivate Whether to deactivate the environment before
  *                         deleting it.
  *
  * @throws EnvironmentStateException
  *
  * @return array
  */
 public function delete($deactivate = false)
 {
     if ($this->isActive()) {
         if (!$deactivate) {
             throw new EnvironmentStateException('Active environments cannot be deleted');
         }
         // Deactivate the environment before deleting. Platform.sh will
         // queue the operations, so there should be no need to wait.
         $this->deactivate();
     }
     return parent::delete();
 }
コード例 #4
0
ファイル: Api.php プロジェクト: commerceguys/platform-cli
 /**
  * Get a nested property of a resource, via a dot-separated string path.
  *
  * @param ApiResource $resource
  * @param string      $propertyPath
  * @param bool        $lazyLoad
  *
  * @throws \InvalidArgumentException if the property is not found.
  *
  * @return mixed
  */
 public static function getNestedProperty(ApiResource $resource, $propertyPath, $lazyLoad = true)
 {
     if (!strpos($propertyPath, '.')) {
         return $resource->getProperty($propertyPath, true, $lazyLoad);
     }
     $parents = explode('.', $propertyPath);
     $propertyName = array_shift($parents);
     $property = $resource->getProperty($propertyName, true, $lazyLoad);
     if (!is_array($property)) {
         throw new \InvalidArgumentException(sprintf('Invalid path "%s": the property "%s" is not an array.', $propertyPath, $propertyName));
     }
     $value = Util::getNestedArrayValue($property, $parents, $keyExists);
     if (!$keyExists) {
         throw new \InvalidArgumentException('Property not found: ' . $propertyPath);
     }
     return $value;
 }