Пример #1
0
 public function testIsJSON()
 {
     $this->assertTrue(Json::isJSON('{"database":{"driver":"pdo_mysql","host":"localhost"},"devMode":true}'));
     $this->assertTrue(Json::isJSON('[]'));
     $this->assertTrue(Json::isJSON('{}'));
     $this->assertTrue(Json::isJSON('true'));
     $this->assertFalse(Json::isJSON('some string'));
     $this->assertTrue(Json::isJSON(true));
     $this->assertEquals('true', json_encode(true));
     $this->assertFalse(Json::isJSON(false));
     $this->assertEquals('false', json_encode(false));
 }
Пример #2
0
 public function run($job)
 {
     $serviceName = $job['service_name'];
     if (!$this->getServiceFactory()->checkExists($serviceName)) {
         throw new NotFound();
     }
     $service = $this->getServiceFactory()->create($serviceName);
     $serviceMethod = $job['method'];
     if (!method_exists($service, $serviceMethod)) {
         throw new NotFound();
     }
     $data = $job['data'];
     if (Json::isJSON($data)) {
         $data = Json::decode($data, true);
     }
     $service->{$serviceMethod}($data);
 }
Пример #3
0
 /**
  * Save JSON content to file
  *
  * @param string | array $path
  * @param string $data
  * @param  integer $flags
  * @param  resource  $context
  *
  * @return bool
  */
 public function putContentsJson($path, $data)
 {
     if (!Utils\Json::isJSON($data)) {
         $data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
     }
     return $this->putContents($path, $data, LOCK_EX);
 }
Пример #4
0
 /**
  * Save JSON content to file
  *
  * @param string | array $path
  * @param string $data
  * @param  integer $flags
  * @param  resource  $context
  *
  * @return bool
  */
 public function putContentsJson($path, $data)
 {
     if (!Utils\Json::isJSON($data)) {
         $data = Utils\Json::encode($data, JSON_PRETTY_PRINT);
     }
     return $this->putContents($path, $data);
 }