예제 #1
0
 /**
  * Test that array values below a path are absorbed.
  *
  * @return void
  */
 public function testPathSubArray()
 {
     $json = new JsonArray(['top1' => ['sub1.1' => 'top1.sub1.1.content']]);
     $json->set('top2', ['sub2.1' => []]);
     $json->set('top2/sub2.2', ['top2.sub2.2.content']);
     $this->assertEquals(['sub2.1' => [], 'sub2.2' => ['top2.sub2.2.content']], $json->get('top2'));
     $this->assertEquals([], $json->get('top2/sub2.1'));
     $this->assertEquals(['top2.sub2.2.content'], $json->get('top2/sub2.2'));
     $json->set('top2', 'top2.content');
     $this->assertEquals('top2.content', $json->get('top2'));
 }
예제 #2
0
파일: TaskList.php 프로젝트: tenside/core
 /**
  * Add the task to the list.
  *
  * @param string         $type     The type name.
  *
  * @param JsonArray|null $metaData The (optional) meta data.
  *
  * @return string
  *
  * @throws \InvalidArgumentException When no task instance can be created from the meta data.
  */
 public function queue($type, JsonArray $metaData = null)
 {
     $taskId = $this->generateId();
     if (null === $metaData) {
         $metaData = new JsonArray();
     }
     $metaData->set(Task::SETTING_ID, $taskId)->set(Task::SETTING_TYPE, $type)->set('status', Task::STATE_PENDING)->set(Task::SETTING_CREATED_AT, date('c'));
     $taskFile = new JsonFile($this->taskIdToFileName($taskId), null);
     $taskFile->setData($metaData->getData());
     $taskFile->save();
     if (!$this->createTaskFromMetaData($taskFile)) {
         unlink($taskFile->getFilename());
         throw new \InvalidArgumentException('Could not create task of type "' . $metaData->get('type') . '"');
     }
     $this->getConfig()->set($taskId, $metaData->getData());
     return $taskId;
 }
예제 #3
0
 /**
  * Convert the data of a complete package to the passed json array.
  *
  * @param CompletePackageInterface $package The package to process.
  *
  * @param JsonArray                $data    The json array to push the data to.
  *
  * @return void
  */
 private function convertCompletePackage(CompletePackageInterface $package, $data)
 {
     $data->set('description', $package->getDescription());
     $data->set('license', $package->getLicense());
     if ($keywords = $package->getKeywords()) {
         $data->set('keywords', $keywords);
     }
     if ($homepage = $package->getHomepage()) {
         $data->set('homepage', $homepage);
     }
     if ($authors = $package->getAuthors()) {
         $data->set('authors', $authors);
     }
     if ($support = $package->getSupport()) {
         $data->set('support', $support);
     }
     if ($extra = $package->getExtra()) {
         $data->set('extra', $extra);
     }
     $data->set('abandoned', $package->isAbandoned());
     if ($package->isAbandoned()) {
         $data->set('replacement', $package->getReplacementPackage());
     }
 }
예제 #4
0
파일: SourceJson.php 프로젝트: tenside/core
 /**
  * {@inheritDoc}
  */
 public function set($path, $value)
 {
     $this->data->set($path, $value);
     return $this;
 }
예제 #5
0
파일: Task.php 프로젝트: tenside/core
 /**
  * Set the task state.
  *
  * @param string $status The status code.
  *
  * @return void
  */
 protected function setStatus($status)
 {
     $this->file->set('status', $status);
 }
 /**
  * Create a project.
  *
  * NOTE: This method will become inaccessible after the returned task has been run successfully.
  *
  * @param Request $request The request.
  *
  * @return JsonResponse
  *
  * @throws NotAcceptableHttpException When the installation is already complete.
  *
  * @ApiDoc(
  *   section="install",
  *   statusCodes = {
  *     201 = "When everything worked out ok",
  *     406 = "When the installation is already been completed"
  *   },
  * )
  * @ApiDescription(
  *   request={
  *     "project" = {
  *       "description" = "The project to install.",
  *       "children" = {
  *         "name" = {
  *           "dataType" = "string",
  *           "description" = "The name of the project to install.",
  *           "required" = true
  *         },
  *         "version" = {
  *           "dataType" = "string",
  *           "description" = "The version of the project to install (optional).",
  *           "required" = false
  *         }
  *       }
  *     }
  *   },
  *   response={
  *     "task" = {
  *       "dataType" = "string",
  *       "description" = "The id of the created install task"
  *     }
  *   }
  * )
  */
 public function createProjectAction(Request $request)
 {
     $status = $this->get('tenside.status');
     if (!$status->isTensideConfigured()) {
         throw new NotAcceptableHttpException('Need to configure first.');
     }
     $this->checkUninstalled();
     $result = [];
     $header = [];
     $installDir = $this->getTensideHome();
     $inputData = new JsonArray($request->getContent());
     $taskData = new JsonArray();
     $taskData->set(InstallTask::SETTING_DESTINATION_DIR, $installDir);
     $taskData->set(InstallTask::SETTING_PACKAGE, $inputData->get('project/name'));
     if ($version = $inputData->get('project/version')) {
         $taskData->set(InstallTask::SETTING_VERSION, $version);
     }
     $taskId = $this->getTensideTasks()->queue('install', $taskData);
     $result['task'] = $taskId;
     $header['Location'] = $this->generateUrl('task_get', ['taskId' => $taskId], UrlGeneratorInterface::ABSOLUTE_URL);
     return new JsonResponse(['status' => 'OK', 'task' => $taskId], JsonResponse::HTTP_CREATED, $header);
 }
예제 #7
0
 /**
  * Convert the information of all packages in a repository to an array used by json API.
  *
  * @param RepositoryInterface $repository   The repository holding the packages to convert.
  *
  * @param bool                $requiredOnly If true, return only the packages added to the root package as require.
  *
  * @param null|JsonArray      $upgradeList  The package version to show as upgradable to.
  *
  * @return JsonArray
  */
 public function convertRepositoryToArray(RepositoryInterface $repository, $requiredOnly = false, JsonArray $upgradeList = null)
 {
     $requires = $requiredOnly ? $this->rootPackage->getRequires() : false;
     $packages = new JsonArray();
     /** @var \Composer\Package\PackageInterface $package */
     foreach ($repository->getPackages() as $package) {
         $name = $package->getPrettyName();
         $esc = $packages->escape($name);
         if (false === $requires || isset($requires[$name])) {
             $upgradeVersion = null;
             if ($upgradeList && $upgradeList->has($esc)) {
                 $upgradeVersion = $upgradeList->get($esc);
             }
             $packages->set($esc, $this->convertPackageToArray($package, $upgradeVersion)->getData());
         }
     }
     return $packages;
 }
예제 #8
0
 /**
  * Ensure the home path has been set in the passed meta data.
  *
  * @param JsonArray $metaData The meta data to examine.
  *
  * @return void
  */
 private function ensureHomePath(JsonArray $metaData)
 {
     if ($metaData->has(AbstractPackageManipulatingTask::SETTING_HOME)) {
         return;
     }
     $metaData->set(AbstractPackageManipulatingTask::SETTING_HOME, $this->home->homeDir());
 }
예제 #9
0
 /**
  * Ensure the home path has been set in the passed meta data.
  *
  * @param JsonArray $metaData The meta data to examine.
  *
  * @return void
  */
 private function ensureHomePath(JsonArray $metaData)
 {
     if ($metaData->has(RequirePackageTask::SETTING_HOME)) {
         return;
     }
     $metaData->set(RequirePackageTask::SETTING_HOME, $this->home->homeDir());
 }
예제 #10
0
 /**
  * {@inheritDoc}
  */
 public function uninstall(RepositoryInterface $repo, UninstallOperation $operation)
 {
     $this->packageInformation->set($this->packageInformation->escape($operation->getPackage()->getPrettyName()), ['type' => 'uninstall', 'package' => $this->dumper->dump($operation->getPackage())]);
     parent::uninstall($repo, $operation);
 }