Example #1
0
 public function testArrayKV()
 {
     $jsonData = '{
                  "responseData":{
                     "vhostList":[
                         {"id":"2","name":"gotcms.staging",
                         "port":"80","status":"Ok","default":"0",
                         "zendDefined":true,"zendManaged":true,"ssl":false,
                         "created":"2015-07-15T12:43:28+00:00",
                         "lastUpdated":"2015-07-23T11:53:18+00:00",
                         "createdTimestamp":"1436964208",
                         "lastUpdatedTimestamp":"1437652398",
                         "servers":[{"id":"0",
                                     "status":"Ok",
                                     "name":"web-staging",
                                     "lastMessage":""}]}], 
                    "total": 1
                }}';
     $expectedOutput = "vhostList[0][id]=2\nvhostList[0][name]=gotcms.staging\nvhostList[0][port]=80\nvhostList[0][status]=Ok\nvhostList[0][default]=0\nvhostList[0][zendDefined]=1\nvhostList[0][zendManaged]=1\nvhostList[0][ssl]=\nvhostList[0][created]=2015-07-15T12:43:28+00:00\nvhostList[0][lastUpdated]=2015-07-23T11:53:18+00:00\nvhostList[0][createdTimestamp]=1436964208\nvhostList[0][lastUpdatedTimestamp]=1437652398\nvhostList[0][servers][0][id]=0\nvhostList[0][servers][0][status]=Ok\nvhostList[0][servers][0][name]=web-staging\nvhostList[0][servers][0][lastMessage]=\ntotal=1\n";
     $items = json_decode($jsonData, true);
     $output = Utils::array2KV($items['responseData']);
     $this->assertEquals($output, $expectedOutput);
 }
Example #2
0
 /**
  *
  * @param MvcEvent $event
  */
 public function preFinish(MvcEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof HttpResponse) {
         $response->setContent($response->getBody());
     }
     $match = $event->getRouteMatch();
     if ($match) {
         $outputFormat = $match->getParam('output-format');
         if ($outputFormat != "kv") {
             return;
         }
         $output = "";
         $content = $response->getContent();
         $data = json_decode($content, true);
         if (isset($data['responseData'])) {
             $output = Utils::array2KV($data['responseData']);
         }
         $response->setContent($output);
     }
 }
Example #3
0
 // compatibility with v0.2.x
 $config = null;
 if (file_exists($root_directory . '/config.yaml')) {
     echo "DEPRECATE WARNING: Please move 'hook-ext/config.yaml' file to 'hook-ext/config/config.yaml'." . PHP_EOL;
     // TODO: remove on v0.4.x
     $config = Utils::parse_yaml($root_directory . '/config.yaml');
 } else {
     $config = Utils::parse_yaml($root_directory . '/config/config.yaml');
 }
 // try to read environment-specific configuration
 $environment_config_file = $root_directory . '/config/config.' . Project::getEnvironment() . '.yaml';
 if (file_exists($environment_config_file)) {
     $environment_config = Utils::parse_yaml($environment_config_file);
     $config = array_replace_recursive($config, $environment_config);
 }
 $stats = $client->post('apps/deploy', array('modules' => $module_sync, 'schema' => Utils::parse_yaml($root_directory . '/schema.yaml'), 'schedule' => $schedule, 'config' => $config, 'security' => Utils::parse_yaml($root_directory . '/security.yaml'), 'packages' => Utils::parse_yaml($root_directory . '/packages.yaml')));
 // remove auto-generated PHP files
 if (count($js_converted_modules) > 0) {
     foreach ($js_converted_modules as $module) {
         unlink($module);
     }
 }
 if (isset($stats->error)) {
     Console::error($stats->error);
 }
 if (isset($stats->schedule)) {
     Console::output("Schedule updated.");
 }
 if (isset($stats->schema) && $stats->schema > 0) {
     Console::output($stats->schema . " collection(s) migrated.");
 }
Example #4
0
            } catch (Exception $e) {
                echo "Failed.";
            }
            echo PHP_EOL;
        }
        if (isset($options['data']) && $options['data']) {
            $current_row = 0;
            $total_rows = count($options['data']);
            foreach ($options['data'] as $data) {
                // Look for special data fields
                foreach ($data as $field => $value) {
                    if (preg_match('/\\!upload ([^$]+)/', $value, $file)) {
                        $filepath = Project::root(Project::DIRECTORY_NAME) . '/seeds/' . $file[1];
                        // stop when file doens't exists
                        if (!file_exists($filepath)) {
                            throw new Exception("File not found: '{$filepath}'");
                        }
                        $mime_type = Utils::mime_type($filepath);
                        $data[$field] = 'data:' . $mime_type . ';base64,' . base64_encode(file_get_contents($filepath));
                    }
                }
                $client->post('collection/' . $collection, array('data' => $data));
                $current_row += 1;
                $percent = round($current_row / $total_rows * 100);
                echo "Seeding '{$collection}': " . "{$percent}%" . str_repeat("\r", strlen($percent) + 1);
            }
        }
        echo PHP_EOL;
    }
    echo "Done." . PHP_EOL;
});
Example #5
0
            //
            // Read or extract certificate file
            // --------------------------------
            //
            if (file_exists($value)) {
                Console::output("Reading certificate file...");
                $ext = pathinfo($value, PATHINFO_EXTENSION);
                if ($ext == 'p12') {
                    $results = array();
                    $worked = openssl_pkcs12_read(file_get_contents($value), $results, null);
                    if ($worked) {
                        $value = $results['cert'] . $results['pkey'];
                    } else {
                        Console::error(openssl_error_string());
                    }
                } else {
                    if ($ext == 'pem') {
                        $value = file_get_contents($value);
                    }
                }
            }
            array_push($configs_to_add, array('name' => $name, 'value' => $value));
        }
    }
    foreach ($configs_to_add as $config) {
        Utils::array_set($configs, $config['name'], $config['value']);
    }
    $dumper = new Symfony\Component\Yaml\Dumper();
    file_put_contents($config_file, str_replace("  ", " ", $dumper->dump($configs, 10)));
    Console::output("Written successfully at: '{$config_file}'");
});