/** * @covers Component\Remote\BurzeDzisNet\Storm::__construct */ public function test__construct() { $storm = new Storm(14, 80.72, 'NE', 10, 50); $this->assertSame(14, $storm->lightnings()); $this->assertSame('NE', $storm->direction()); $this->assertSame(80.72, $storm->distance()); $this->assertSame(10, $storm->period()); $this->assertSame(50, $storm->radius()); }
<?php $entity = $_POST['entity']; $field = $_POST['attribute']; $type = $_POST['type']; Storm::get($entity)->add($field, $type);
<?php $name = $_POST['name']; Storm::get($name);
<?php foreach (Storm::all() as $item) { $item->regenerate(); }
<?php $entities = array(); foreach (Storm::all() as $storm) { $entities[] = $storm->getName(); } sort($entities); echo json_encode($entities);
<?php $name = $_POST['name']; $result = array(); if (Storm::exists($name)) { foreach ($name::SELECT() as $r) { $result[$r->ID()] = $r->row; } } echo json_encode($result);
<?php $entity = $_POST['entity']; $field = $_POST['attribute']; Storm::get($entity)->remove($field);
<?php $entity = $_POST['entity']; $result = Storm::get($entity)->drop(); echo json_encode($result);
public function regenerate() { // Native entities can't be regenerated if ($this->model['native']) { return false; } $filename_extended = self::$dir_base . $this->name . '/extended.class.php'; $filename_auto = self::$dir_base . $this->name . '/auto.class.php'; if (!file_exists($filename_extended)) { $code = '<?php /** * Class: ' . $this->name . ' * Created on: ' . date('r') . ' */ class ' . $this->name . ' extends ' . $this->name . '_auto { } '; file_put_contents($filename_extended, $code); chmod($filename_extended, 0777); } $fields = array(); foreach ($this->model['fields'] as $name => $type) { $fields[$name] = array('type' => $type, 'native' => Storm::get($type)->isNative()); } $code = '<?php /** * # CAUTION # * * Autogenerated code. Any changes in this file will be lost. * To add extra behaviour, please, edit the extended class (extended.class.php) * */ class ' . $this->name . '_auto { public static $fields = ' . var_export($fields, true) . '; protected static $data = array(); protected $id; protected $timestamp; protected $operation; public $row; public function __construct(&$row) { $this->id = $row[\'id\']; $this->timestamp = $row[\'__timestamp__\']; $this->operation = $row[\'__operation__\']; $this->row = $row; } public function RAW($field) { if (array_key_exists($field, $this->row)) { return $this->row[$field]; } return null; } public static function PREFETCH($field, $collection) { $IDs = array(); foreach ($collection as $item) { $IDs[] = $item->RAW($field); } $IDs = array_unique($IDs); if (count($IDs)) { $implode = implode(\',\', $IDs); return self::SELECT(" Id IN ($implode) "); } return array(); } public static function SELECT($where=null) { $sql = "SELECT * FROM `' . Database::escape($this->name) . '`"; if ($where !== null) $sql .= " WHERE ".$where; $select = array(); $result = Database::sql($sql); while ($result && $row=$result->fetch_assoc()) { $id = $row[\'id\']; if (!array_key_exists($id, self::$data)) self::$data[$id] = new ' . $this->name . '($row); $select[] = &self::$data[$id]; } return $select; } public static function COUNT($where=null) { $sql = "SELECT COUNT(*) FROM `' . Database::escape($this->name) . '`"; if ($where !== null) $sql .= " WHERE ".$where; $result = Database::sql($sql); if ($result && $row=$result->fetch_row()) { return $row[0]; } return null; } public static function INSERT() { $sql = "INSERT INTO `' . $this->name . '` (`id`, `__timestamp__`, `__operation__`) VALUES (NULL, ".time().", \'INSERT\')"; $result = Database::sql($sql); $id = Database::getInsertId(); return self::ROW($id); } public static function ROW($id) { $id = intval($id); if (array_key_exists($id, self::$data)) { return self::$data[$id]; } else { $rows = self::SELECT("id=\'".Database::escape($id)."\'"); if (count($rows)) { return $rows[0]; } else { return null; } } } public function DELETE($physical=true) { if ($physical) { $sql = "DELETE FROM `' . $this->name . '` WHERE id=\'".$this->id."\'"; unset(self::$data[$this->id]); } else { $sql = "UPDATE `' . $this->name . '` SET `__timestamp__` = ".time().", `__operation__` = \'DELETE\' WHERE `id`=\'".$this->id."\'"; } Database::sql($sql); } /* Deprecated */ public final function getId() { return intval($this->id); } public final function ID() { return intval($this->id); } public final function TIMESTAMP() { return intval($this->timestamp); } public final function OPERATION() { return $this->operation; } public final function getClassName() { return \'' . $this->name . '\'; } public function toString() { return "' . $this->name . '[{$this->id}]"; } // Setters and Getters '; foreach ($this->model['fields'] as $field_name => $field_type) { $type = Storm::get($field_type); if ($type->model['native']) { $code .= str_replace(array('__table_name__', '__field_name__'), array($this->getName(), $field_name), $type->model['methods']) . "\n\n"; } else { $code .= ' public function set' . $field_name . '($value) { if (is_object($value) && $value->getClassName() == \'' . $field_type . '\') { $id = $value->getId(); $sql = "UPDATE `' . $this->name . '` SET `' . $field_name . '`=\'".$id."\', `__timestamp__` = ".time()." WHERE `id`=\'".$this->id."\'"; Database::sql($sql); $this->row[\'' . $field_name . '\'] = $id; } else if ($value === null) { $sql = "UPDATE `' . $this->name . '` SET `' . $field_name . '`=\'0\', `__timestamp__` = ".time()." WHERE `id`=\'".$this->id."\'"; Database::sql($sql); $this->row[\'' . $field_name . '\'] = 0; } } public function get' . $field_name . '() { if ($this->row[\'' . $field_name . '\'] == 0) { return null; } else { return ' . $field_type . '::ROW($this->row[\'' . $field_name . '\']); } } '; } } $code .= ' } '; file_put_contents($filename_auto, $code); chmod($filename_auto, 0777); return true; }
echo shell_exec("git init --bare .git"); echo "\n# Adding git hook 'post-receive'...\n"; $hook_file = $cwd . '/.git/hooks/post-receive'; $hook_data = "#!/bin/sh\nGIT_WORK_TREE={$cwd} git checkout -f\ncd {$cwd}\n"; file_put_contents($hook_file, $hook_data); chmod($hook_file, 0755); echo shell_exec("ls -la {$hook_file}"); echo "\n# Upload your repo\n\n"; echo "= Execute this commands in your local machine:================================\n\n"; echo "git remote add REMOTE_NAME ssh://USER@SERVER{$cwd}/.git\n"; echo "git push REMOTE_NAME YOUR_PREFERRED_BRANCH:master\n\n"; command('When the repo will be uploaded, press ENTER:'); echo "\n# Configuring database\n"; $host = command('Host: '); $db = command('Database: '); $user = command('User: '******'Pass: '******'class/Main.class.php'; Main::goCli(); Database::configure($host, $db, $user, $pass); echo "\n# Installing TreeWeb...\n"; foreach (Storm::all() as $s) { $s->install(); } echo "\n# Adding post-receive line...\n"; file_put_contents($hook_file, "php.ORIG.5_4 -n install.php --install\n", FILE_APPEND); echo "\n\n TreeWeb is now installed\n\n"; } } } }