Exemplo n.º 1
0
 /**
  * @depends testNodeFindByUUID
  * @param Models\Node $node
  */
 public function testNodeParameters(Models\Node $node)
 {
     $this->assertEquals(null, $node->getAvailabilityZone(), 'getAvailabilityZone did not return expected result');
     $this->assertEquals(2, $node->getCpu(), 'getCpu did not return expected result');
     $this->assertEquals(16, $node->getCurrentNumContainers(), 'getCurrentNumContainers did not return expected result');
     $this->assertEquals('Mon, 13 Apr 2015 10:44:56 +0000', $node->getDeployedDatetime(), 'getDeployedDatetime did not return expected result');
     $this->assertEquals(null, $node->getDestroyedDatetime(), 'getDestroyedDatetime did not return expected result');
     $this->assertEquals(39, $node->getDisk(), 'getDisk did not return expected result');
     $this->assertEquals('native-0.2', $node->getDockerExecdriver(), 'getDockerExecdriver did not return expected result');
     $this->assertEquals('aufs', $node->getDockerGraphdriver(), 'getDockerGraphdriver did not return expected result');
     $this->assertEquals('1.5.0', $node->getDockerVersion(), 'getDockerVersion did not return expected result');
     $this->assertEquals('3cb9e362-matthewbaggett.node.tutum.io', $node->getExternalFqdn(), 'getExternalFqdn did not return expected result');
     $this->assertEquals(['cpu' => 29.0948290433331, 'disk' => 16026988544.0, 'memory' => 1054019584], arrayify($node->getLastMetric()), 'getLastMetric did not return expected result');
     $this->assertEquals('Thu, 30 Jul 2015 11:32:43 +0000', $node->getLastSeen(), 'getLastSeen did not return expected result');
     $this->assertEquals(2048, $node->getMemory(), 'getMemory did not return expected result');
     $this->assertEquals('/api/v1/nodecluster/0d10fa1c-2783-4195-b5d8-7541a1890c41/', $node->getNodeCluster(), 'getNodeCluster did not return expected result');
     $this->assertEquals('/api/v1/nodetype/digitalocean/2gb/', $node->getNodeType(), 'getNodeType did not return expected result');
     $this->assertEquals('178.62.105.101', $node->getPublicIp(), 'getPublicIp did not return expected result');
     $this->assertEquals('/api/v1/region/digitalocean/lon1/', $node->getRegion(), 'getRegion did not return expected result');
     $this->assertEquals('/api/v1/node/3cb9e362-d4ef-4e4b-9ee6-280738b53172/', $node->getResourceUri(), 'getResourceUri did not return expected result');
     $this->assertEquals('Deployed', $node->getState(), 'getState did not return expected result');
     $this->assertEquals([0 => ['name' => 'digitalocean'], 1 => ['name' => 'lon1'], 2 => ['name' => 'Prezzler']], arrayify($node->getTags()), 'getTags did not return expected result');
     $this->assertEquals(null, $node->getTunnel(), 'getTunnel did not return expected result');
     $this->assertEquals('3cb9e362-d4ef-4e4b-9ee6-280738b53172', $node->getUuid(), 'getUuid did not return expected result');
 }
Exemplo n.º 2
0
 public function generateGettersSetters($response)
 {
     $type = get_called_class();
     $bits = explode("\\", $type);
     $type = end($bits);
     $type = ucfirst($type);
     $type_lower = strtolower($type);
     echo "<pre>";
     foreach (get_object_vars($response) as $var => $a) {
         $variableName = $this->_snakeToCamel($var, true);
         echo "protected \${$variableName};\n";
     }
     echo "\n";
     foreach (get_object_vars($response) as $var => $a) {
         $variableName = $this->_snakeToCamel($var, true);
         $functionName = $this->_snakeToCamel($var, false);
         echo "public function get{$functionName}(){\n";
         echo "  return \$this->{$variableName};\n";
         echo "}\n\n";
         echo "public function set{$functionName}(\${$variableName}){\n";
         echo "  \$this->{$variableName} = \${$variableName};\n";
         echo "}\n\n";
     }
     echo "  \n";
     echo "public function get{$type}FromResponse(\$response, Models\\{$type} \${$type_lower} = null){\n";
     echo "  if(\${$type_lower} === null) {\n";
     echo "    \${$type_lower} = new Models\\{$type}();\n";
     echo "  }\n";
     echo "  \n";
     foreach (get_object_vars($response) as $var => $a) {
         $variableName = $this->_snakeToCamel($var, true);
         $functionName = $this->_snakeToCamel($var, false);
         echo "  \${$type_lower}->set{$functionName}(\$response->{$var});\n";
     }
     echo "  \n";
     echo "  return \${$type_lower};\n";
     echo "}\n";
     echo "\n";
     echo "/**\n";
     echo " * @depends \n";
     echo " * @param Models\\{$type} \${$type_lower}\n";
     echo " */\n";
     echo "public function test{$type}Parameters(Models\\{$type} \${$type_lower}){\n";
     foreach (get_object_vars($response) as $var => $a) {
         $variableName = $this->_snakeToCamel($var, true);
         $functionName = $this->_snakeToCamel($var, false);
         $comment = "get{$functionName} did not return expected result";
         if (is_object($a) || is_array($a) && is_object(end($a))) {
             echo "  \$this->assertEquals(" . var_export_compact(arrayify($a)) . ", arrayify(\${$type_lower}->get{$functionName}()), '{$comment}');\n";
         } else {
             echo "  \$this->assertEquals(" . var_export_compact($a) . ", \${$type_lower}->get{$functionName}(), '{$comment}');\n";
         }
     }
     echo "}\n";
     echo "\n";
     exit;
 }
Exemplo n.º 3
0
 /**
 * Sky Mustache Constructor
 * @param string $mustache mustache filename (relative to calling php file or codebase)
        OR mustache markup string containing at least one {{tag}}
 * @param mixed $data object with properties/methods or array of values/functions
 * @param mixed $partials see usage notes above
 * @param mixed $path see usage notes above
 * @return string
 */
 public function __construct($mustache, $data, $partials = null, $path = null)
 {
     // if $partials is not an associative array, assume it is $path
     if (!\is_assoc($partials)) {
         // $path was provided as the 3rd param
         // ignore the 4th param
         $path = $partials;
         $partials = null;
     }
     $paths = \arrayify($path);
     // get the mustache markup
     $markup = $this->getMarkup($mustache);
     if (!$markup) {
         // the requested mustache file is not in the include path
         // so let's try to find it relative to the path(s) provided
         $markup = $this->getMarkup($mustache, $paths);
     }
     $this->markup = $markup;
     $this->data = $data;
     $this->partials = $this->getPartials($markup, $paths, $partials);
 }
Exemplo n.º 4
0
 /**
  * Pushes args onto the array
  * @param   string  $arr
  * @param   array   $args
  * @return  $this
  */
 private function _append($arr, $args)
 {
     foreach ($args as $arg) {
         $arg = arrayify($arg);
         foreach ($arg as $a) {
             $this->{$arr}[] = $a;
         }
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * aql::insert/update on the save array depending on what needs to be done
  * recursive because of sub objects / queries
  * @param   array   $save_array     array to save
  * @param   array   $ids            ids to pass through
  * @return  array                   updated save array
  */
 private final function saveArray($save_array, $ids = array())
 {
     $is_dev = $this->isDev();
     // copy out objects
     $objects = $save_array['__objects__'];
     unset($save_array['__objects__']);
     // helper function
     $addRecordInfo = function ($table_block, $is_update = false) {
         $fields = array('update' => array('mod__person_id', 'update__person_id'), 'insert' => array('insert__person_id'));
         $key = $is_update ? 'update' : 'insert';
         $time_field = $key . '_time';
         if (!$table_block['fields'][$time_field]) {
             $table_block['fields'][$time_field] = aql::now();
         }
         if (!defined('PERSON_ID') || !is_numeric(PERSON_ID)) {
             return $table_block;
         }
         $id = PERSON_ID;
         $fields = $fields[$key];
         foreach ($fields as $field) {
             $table_block['fields'][$field] = $table_block['fields'][$field] ?: $id;
         }
         return $table_block;
     };
     foreach ($save_array as $table => $info) {
         // make sure this is an array
         $info['fields'] = arrayify($info['fields']);
         foreach ($ids as $n => $v) {
             if (is_array($this->_ignore['fields']) && in_array($n, $this->_ignore['fields'])) {
                 // since ids are added to each table in case of foreign keys
                 // abort if they are being ignored in this model
                 continue;
             }
             // add the id to the table block iff there are already fields
             if ($info['fields'] && !$info['fields'][$n]) {
                 $save_array[$table]['fields'][$n] = $v;
                 $info['fields'][$n] = $v;
             }
         }
         if ($info['fields']) {
             $is_update = $info['id'] && is_numeric($info['id']);
             $info = $addRecordInfo($info, $is_update);
             if ($is_update) {
                 aql::update($table, $info['fields'], $info['id'], true);
             } else {
                 $rs = aql::insert($table, $info['fields'], true);
                 $save_array[$table]['id'] = $info['id'] = $rs[0][$table . '_id'];
             }
         }
         $ids[$table . '_id'] = $info['id'];
         if (is_array($info['subs'])) {
             foreach ($info['subs'] as $i => $sub) {
                 $save_array[$table]['subs'][$i] = $this->saveArray($sub, $ids);
             }
         }
     }
     if (is_array($objects)) {
         foreach ($objects as $o) {
             if (!$o['data']) {
                 continue;
             }
             $tmp = Model::get($o['object']);
             $tmp->_data = $o['data'];
             $tmp->loadIDs($ids);
             $pt = $tmp->getPrimaryTable();
             $pt_id = $pt . '_id';
             if (!$tmp->{$pt_id} && $this->{$pt_id}) {
                 $tmp->{$pt_id} = $this->{$pt_id};
             }
             $tmp->save(true);
             if ($tmp->_errors) {
                 $this->addErrors($tmp->_errors);
                 $this->failTransaction();
             }
         }
     }
     $save_array['objects'] = $objects;
     return $save_array;
 }
 /**
  * Prepares the callback value to be a list as necessary
  * to be used in: field in (values)
  * @param   mixed   $val (array or string)
  * @return  string
  */
 public static function prepVal($val)
 {
     $quote = function ($val) {
         return "'{$val}'";
     };
     return sprintf('(%s)', implode(',', array_map($quote, \arrayify($val))));
 }
/**
 * Escapes the given command and executes it on the command line
 * @param mixed $command command string or array of command strings
 * @param array $output referenced array to be filled with every line of output
 * @return string
 */
function safe_exec($command, &$output = array())
{
    $commands = arrayify($command);
    $command_str = null;
    foreach ($commands as $command) {
        $command_str .= escapeshellcmd($command) . '; ';
    }
    return exec($command_str, $output);
}
Exemplo n.º 8
0
 /**
  * Directly delete memcache value
  * Only use this if avoiding transactions on purpose
  * Otherwise use \Sky\Memcache::delete()
  * @param   string  $key
  * @return  Boolean
  */
 public static function deleteMemValue($key)
 {
     if (!static::isMemcacheEnabled()) {
         return false;
     }
     $keys = \arrayify(static::getAppSpecificKey($key));
     foreach ($keys as $k) {
         static::getMemcache()->delete($k, null);
     }
 }
Exemplo n.º 9
0
Arquivo: Inc.php Projeto: hshoghi/cms
 /**
  * Adds vf css and js to the page and whatever other css/js is passed in
  * @param   array $resources    associative
  * @return  \Sky\Page
  */
 public static function addPageResources(array $resources = array())
 {
     $css = \arrayify($resources['css']) ?: array();
     $js = \arrayify($resources['js']) ?: array();
     $css[] = '/' . static::$resource_path . 'css/vf.css';
     $js[] = '/' . static::$resource_path . 'js/vf.js';
     return static::getPage()->setConfig(array('css' => $css, 'js' => $js));
 }