YAMLLoad() public static méthode

The load method, when supplied with a YAML stream (string or file), will do its best to convert YAML in a file into a PHP array. Pretty simple. Usage: $array = Spyc::YAMLLoad('lucky.yaml'); print_r($array);
public static YAMLLoad ( string $input ) : array
$input string Path of YAML file or string containing YAML
Résultat array
 /**
  * edit
  *
  * @return void
  */
 public function edit()
 {
     //リクエストセット
     if ($this->request->is('post')) {
         //登録処理
         if (!$this->request->data['SiteSetting']['only_session']) {
             unset($this->request->data['SiteSetting']['only_session']);
             $this->Session->write('debug', null);
             //application.ymlに書き込み
             $conf = Spyc::YAMLLoad(APP . 'Config' . DS . 'application.yml');
             $conf['debug'] = (int) $this->request->data['SiteSetting']['debug']['0']['value'];
             $file = new File(APP . 'Config' . DS . $this->appYmlPrefix . 'application.yml', true);
             $file->write(Spyc::YAMLDump($conf));
             $this->SiteManager->saveData();
         } else {
             $this->SiteSetting->validateDeveloper($this->request->data);
             if (!$this->SiteSetting->validationErrors) {
                 $this->Session->write('debug', (int) $this->request->data['SiteSetting']['debug']['0']['value']);
                 $this->NetCommons->setFlashNotification(__d('net_commons', 'Successfully saved.'), array('class' => 'success'));
                 $this->redirect($this->referer());
             } else {
                 $this->NetCommons->handleValidationError($this->SiteSetting->validationErrors);
             }
         }
     } else {
         $this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(array('SiteSetting.key' => array('debug')));
         $onlySession = $this->Session->read('debug');
         $this->request->data['SiteSetting']['only_session'] = isset($onlySession);
         if ($this->request->data['SiteSetting']['only_session']) {
             $this->request->data['SiteSetting']['debug']['0']['value'] = $onlySession;
         }
     }
 }
 function remoteFunction(&$controller, $options)
 {
     $javascript_options = JavascriptHelper::optionsForAjax($options);
     $update = '';
     if (isset($options['update']) && is_string($options['update'])) {
         require_once 'vendor/spyc.php';
         $val = @Spyc::YAMLLoad($options['update']);
         if (!empty($val)) {
             // it's a YAML array, so load it into options['update']
             $options['update'] = $val;
         }
     }
     if (isset($options['update']) && is_array($options['update'])) {
         $update = array();
         if (isset($options['update']['success'])) {
             $update[] = "success:'{$options['update']['success']}'";
         }
         if (isset($options['update']['failure'])) {
             $update[] = "failure:'{$options['update']['failure']}'";
         }
         $update = implode(',', $update);
     } else {
         if (isset($options['update'])) {
             $update = $options['update'];
         }
     }
     $function = isset($options['update']) ? "new Ajax.Updater('{$update}', " : 'new Ajax.Request(';
     $function .= "'" . UrlHelper::urlFor($controller, $options['url']) . "'";
     $function .= ', ' . $javascript_options . ')';
     $function = (isset($options['before']) ? "{$options['before']}; " : '') . $function;
     $function .= isset($options['after']) ? "; {$options['after']};" : '';
     $function = isset($options['condition']) ? 'if(' . $options['condition'] . '){' . $function . '}' : $function;
     $function = isset($options['confirm']) ? 'if(confirm' . $options['condition'] . '){' . $function . '}' : $function;
     return $function;
 }
 protected function _read()
 {
     $settingsFile = CONFIGS . DS . 'settings.php';
     include $settingsFile;
     if (!isset($settings)) {
         trigger_error(sprintf(__('Missing settings file[%s] or $settings could not be found', true), $settingsFile));
         return array();
     }
     $records = $this->find('all');
     foreach ($records as $record) {
         switch ($record['Setting']['name']) {
             case 'per_page_options':
                 $settings[$record['Setting']['name']] = explode(',', $record['Setting']['value']);
                 break;
             case 'issue_list_default_columns':
                 $settings[$record['Setting']['name']] = Spyc::YAMLLoad($record['Setting']['value']);
                 // array_slice(array_map('trim',explode('- ',$v['Setting']['value'])),1);
                 break;
             default:
                 $settings[$record['Setting']['name']] = $record['Setting']['value'];
         }
     }
     Cache::write(self::$__cacheKey, $settings);
     return $settings;
 }
function i18n($prompt, $lang)
{
    $fileName = 'locales/' . $lang . '.yml';
    // Retrieve complete list of translations as a single string
    $yaml = Spyc::YAMLLoad($fileName);
    $contents = $yaml[$lang];
    $promptArray = explode(".", $prompt);
    $result = $contents;
    for ($i = 0; $i < count($promptArray); $i++) {
        if (is_array($result)) {
            $result = $result[$promptArray[$i]];
        } else {
            if (isset($result)) {
                return $result;
            } else {
                return $prompt;
            }
        }
    }
    if (isset($result)) {
        return $result;
    } else {
        return $prompt;
    }
}
function compile_apps_yaml()
{
    # Load Spyc and serialize apps.yaml.
    include 'spyc.lib.php';
    $data = Spyc::YAMLLoad('apps.yaml');
    return serialize($data);
}
Exemple #6
0
 function subTest($p, $s)
 {
     //	we really need do this right and to set up a yaml module that abstracts away the underlying yaml engine
     include_once zoop_dir . '/spyc/spyc.php';
     $array = Spyc::YAMLLoad($_SERVER['HOME'] . '/.zoop/install.yaml');
     print_r($array);
 }
Exemple #7
0
 function find($conditions = null, $fields = array(), $order = null, $recursive = null)
 {
     if ($conditions != 'range') {
         return parent::find($conditions, $fields, $order, $recursive);
     }
     $file = Set::extract($fields, 'file');
     if (empty($file)) {
         $file = ROOT . DS . APP_DIR . DS . 'plugins/mobileip/config/mobile_ips.yml';
     }
     if (!file_exists($file)) {
         return false;
     }
     $cacheDir = $this->getCacheDir();
     $folder = new Folder($cacheDir);
     $folder->create($cacheDir, 0777);
     $cacheFile = $this->getCacheFile();
     if (file_exists($cacheFile) && $this->_getLastModified($file) <= filemtime($cacheFile)) {
         return include $cacheFile;
     }
     $mobile_ips =& Spyc::YAMLLoad($file);
     if (!is_array($mobile_ips)) {
         return false;
     }
     $data = $this->_get_ranges($mobile_ips);
     $file = new File($cacheFile, true);
     $file->write($data);
     $file->close();
     return include $cacheFile;
 }
 /**
  * versionCheck - Get the most current version of nterchange and cache the result.
  *
  * @return 	array 	Information about the newest version of nterchange.
  **/
 function versionCheck()
 {
     require_once 'Cache/Lite.php';
     $options = array('cacheDir' => CACHE_DIR . '/ntercache/', 'lifeTime' => $this->check_version_interval);
     $cache = new Cache_Lite($options);
     $yaml = $cache->get($this->cache_name, $this->cache_group);
     if (empty($yaml)) {
         include_once 'HTTP/Request.php';
         $req = new HTTP_Request($this->check_version_url);
         if (!PEAR::isError($req->sendRequest())) {
             $yaml = $req->getResponseBody();
             $cached = $cache->save($yaml, $this->cache_name, $this->cache_group);
             if ($cached == true) {
                 NDebug::debug('Version check - data is from the web and is now cached.', N_DEBUGTYPE_INFO);
             } else {
                 NDebug::debug('Version check - data is from the web and is NOT cached.', N_DEBUGTYPE_INFO);
             }
         }
     } else {
         NDebug::debug('Version check - data is from the cache.', N_DEBUGTYPE_INFO);
     }
     require_once 'vendor/spyc.php';
     $newest_version_info = @Spyc::YAMLLoad($yaml);
     return $newest_version_info;
 }
 /**
  * Load configuration file by it's type and put it into a Zend_Config object
  *
  * @param  string $configFile Configuration file path
  * @param  string $fileType   Configuration file type
  * @param  string $section    Configuration section to load
  * @return Zend_Config
  */
 public static function load($configFile, $fileType = self::YAML, $section = 'default')
 {
     switch ($fileType) {
         case self::YAML:
             $yaml = file_get_contents($configFile);
             if (extension_loaded('syck')) {
                 $data = syck_load($yaml);
             } else {
                 require_once 'Spyc.php';
                 $data = Spyc::YAMLLoad($yaml);
             }
             require_once 'Zend/Config.php';
             return new Zend_Config($data[$section]);
             break;
         case self::INI:
             require_once 'Zend/Config/Ini.php';
             return new Zend_Config_Ini($configFile, $section);
             break;
         case self::XML:
             require_once 'Zend/Config/Xml.php';
             return new Zend_Config_Xml($configFile, $section);
             break;
         default:
             require_once 'Spizer/Exception.php';
             throw new Spizer_Exception("Configuration files of type '{$fileType}' are not (yet?) supported");
             break;
     }
 }
Exemple #10
0
 /**
  * Load config file
  *
  * Get array from config file and save it to variable
  *
  * @static
  * @access   public
  * @param    string $sConfigPath
  * @param    string $sFormat
  * @return   bool
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private static function load($sConfigPath, $sFormat = 'php')
 {
     $oConfigData = static::findConfigFile($sConfigPath, $sFormat);
     // load config data
     if ($oConfigData !== FALSE) {
         switch ($sFormat) {
             # PHP
             case 'php':
                 $aConfig = (include $oConfigData->getPath());
                 break;
                 # YAML
             # YAML
             case "yml":
                 $aConfig = \Spyc::YAMLLoad($oConfigData->getPath());
                 break;
         }
     }
     // assign data to storage
     if (isset($aConfig)) {
         Helper\Arrays::createMultiKeys(static::$aConfigs, $sConfigPath, $aConfig);
         unset($aConfig);
         Log::insert('Config ' . $sConfigPath . ' (' . $sFormat . ') loaded');
         return TRUE;
     }
     // if there is no data to assign (because the config file does not exists), create ERROR message and return FALSE (or throw exception)
     $sMsg = 'Unable to load ' . $sConfigPath . ' config file with "' . $sFormat . '" format.';
     Log::insert($sMsg, Log::ERROR);
     if (Core::getAppMode() === Core::MODE_DEVELOPMENT) {
         throw new Exception($sMsg);
     }
     return FALSE;
 }
Exemple #11
0
 function __construct()
 {
     # Include the SPYC library for yaml parsing:
     require_once '3rd-party/spyc/spyc.php';
     # Loads an array with the config:
     $this->aConfig = Spyc::YAMLLoad('config.yml');
 }
 /**
  * The method that runs the task
  *
  * @return void
  */
 public function main()
 {
     $this->map = Spyc::YAMLLoad($this->mapFile);
     if (!isset($this->map['symlinks'])) {
         throw new Exception("Invalid symlinks map file", 1);
     }
 }
Exemple #13
0
function doTheHooks($name, $branch, $repo, $transport)
{
    $result = null;
    chdir($repo['dir']);
    ob_start();
    echo "~> git pull origin " . $branch . " 3>&1\n";
    system(__ENV_PATH__ . ' ' . __GIT_PATH__ . ' pull origin ' . $branch . ' 2>&1');
    echo "\n";
    if (file_exists($repo['dir'] . '/' . __HOOKS_FILE__)) {
        $yaml = Spyc::YAMLLoad($repo['dir'] . '/' . __HOOKS_FILE__);
        $cmds = array();
        if (is_array($yaml[$repo['branch']])) {
            $cmds = $yaml[$repo['branch']];
        } elseif (is_array($yaml['all'])) {
            $cmds = $yaml['all'];
        }
        foreach ($cmds as $cmd) {
            echo "~> " . $cmd . "\n";
            system(__ENV_PATH__ . ' ' . $cmd);
            echo "\n";
        }
        $result = ob_get_contents();
        if (is_array($yaml['emails'])) {
            foreach ($yaml['emails'] as $email) {
                $mailer = Swift_Mailer::newInstance($transport);
                $message = Swift_Message::newInstance()->setSubject(sprintf(__MAIL_SUBJECT__, $name))->setFrom(array(__MAIL_FROM_ADDRESS__ => __MAIL_FROM__))->setTo(array($email))->setBody($result);
                $result = $mailer->send($message);
            }
        }
    }
    ob_end_clean();
}
Exemple #14
0
 /**
  * Parse a block of YAML into PHP
  *
  * @param string  $yaml  YAML-formatted string to parse
  * @param string  $mode  Parsing mode to use
  * @return array
  */
 public static function parse($yaml, $mode = null)
 {
     // start measuring
     $hash = Debug::markStart('parsing', 'yaml');
     $mode = $mode ? $mode : self::getMode();
     switch ($mode) {
         case 'loose':
             $result = Spyc::YAMLLoad($yaml);
             break;
         case 'strict':
             $result = sYAML::parse($yaml);
             break;
         case 'transitional':
             try {
                 $result = sYaml::parse($yaml);
             } catch (Exception $e) {
                 Log::error($e->getMessage() . ' Falling back to loose mode.', 'core', 'yaml');
                 $result = Spyc::YAMLLoad($yaml);
             }
             break;
         default:
             $result = Spyc::YAMLLoad($yaml);
     }
     // end measuring
     Debug::markEnd($hash);
     Debug::increment('parses', 'yaml');
     return $result;
 }
 protected function setUp()
 {
     global $SAP_CONFIG;
     $this->config = Spyc::YAMLLoad($SAP_CONFIG);
     echo "sapnwrfc version: " . sapnwrfc_version() . "\n";
     echo "nw rfc sdk version: " . sapnwrfc_rfcversion() . "\n";
 }
Exemple #16
0
 function __construct($database_type, $db_file)
 {
     $Data = Spyc::YAMLLoad(BMARK . 'db.yaml');
     if ($database_type == 'mysql') {
         $this->database_type = $database_type;
         $this->user = $Data['mysqld']['user'];
         $this->pass = $Data['mysqld']['pass'];
         $this->host = $Data['mysqld']['host'];
         $this->port = $Data['mysqld']['port'];
         $this->database = $Data['mysqld']['dbname'];
         $this->connection = '';
     }
     if ($database_type == 'drizzle') {
         $this->database_type = $database_type;
         $this->user = $Data['drizzled']['user'];
         $this->pass = $Data['drizzled']['pass'];
         $this->host = $Data['drizzled']['host'];
         $this->port = $Data['drizzled']['port'];
         $this->database = $Data['drizzled']['dbname'];
         $this->connection = '';
     }
     if (strlen($this->port) <= 0) {
         if (strcmp($this->database_type, "mysql") == 0) {
             $this->port = '3306';
         }
         if (strcmp($this->database_type, "drizzle") == 0) {
             $this->port = '4427';
         }
     }
 }
Exemple #17
0
 static function read($filename)
 {
     if (!file_exists($filename)) {
         trigger_error("YAML error: file '{$filename}' does not exist");
     }
     return Spyc::YAMLLoad($filename);
 }
Exemple #18
0
 /**
  * SysMisNeural::CargarArchivoYAMLAplicacion($Ruta);
  * 
  * Metodo para cargar los archivos YAML que se encuentran dentro de la carpeta Aplicacion
  * @param $Ruta: se utilliza la el nombre de la caperta / archivo
  * Ejemplo: SysMisNeural::CargarArchivoYAMLAplicacion('Configuracion/Archivo.yaml');
  * 
  **/
 public static function CargarArchivoYAMLAplicacion($Ruta)
 {
     //Validacion de Activacion de Cache
     if (__SysNeuralCoreCache__ == 'HABILITADO') {
         $RutaArray = explode('/', $Ruta);
         $AplicacionArray = explode('.', $RutaArray[1]);
         $Llave = md5($AplicacionArray[0]);
         $Cache = new NeuralCacheSimple('NeuralNFZyosSetUp', $Llave);
         $Cache->DefinirTiempoExpiracion(__SysNeuralCoreCacheExpiracion__);
         if ($Cache->ExistenciaCache(base64_encode($Llave))) {
             return $Cache->ObtenerCache(base64_encode($Llave));
         } else {
             //Leemos el archivo de configuracion de accesos y lo convertimos en un array
             $YML = new Spyc();
             $Array = $YML->YAMLLoad(__SysNeuralFileRootAplicacion__ . $Ruta);
             $Cache->GuardarCache($Llave, $Array);
             return $Array;
         }
     } else {
         //Leemos el archivo de configuracion de accesos y lo convertimos en un array
         $YML = new Spyc();
         $Array = $YML->YAMLLoad(__SysNeuralFileRootAplicacion__ . $Ruta);
         return $Array;
     }
 }
function save_data($obj)
{
    global $wpdb;
    require_once "../../../../../wp-load.php";
    require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/class/Spyc.php';
    require_once ABSPATH . 'wp-content/plugins/UiGEN-Core/core-files/defines-const.php';
    if (!current_user_can('manage_options')) {
        echo 'ADMIN BABY !!!';
        die;
    }
    /*	echo '<h2>Save</h2>';
    	echo '<pre>';
    	var_dump($obj['data']);
    	echo '</pre>';*/
    $prop_path = GLOBALDATA_PATH . 'template-hierarchy';
    $posttypes_array = Spyc::YAMLLoad($prop_path . '/arguments/' . $obj['ui_page_name'] . '-slots-properties.yaml');
    //var_dump($posttypes_array[$_POST['slotname']]);
    //echo '<br>---<br>';
    //var_dump($_POST['data']);
    $execute_array = array_merge($posttypes_array[$obj['slotname']], $obj['data']);
    //echo '<br>---<br>';
    //var_dump($execute_array);
    $posttypes_array[$obj['slotname']] = $execute_array;
    //var_dump($posttypes_array);
    file_put_contents($prop_path . '/arguments/' . $obj['ui_page_name'] . '-slots-properties.yaml', Spyc::YAMLDump($posttypes_array));
}
Exemple #20
0
 public static function load($filename)
 {
     // cache object
     #        $oCache = Days_Cache::instance();
     // load configuration file from cache
     #        if ($oCache->isCached($filename)) {
     #            $config = $oCache->getCache($filename);
     #        }
     // load configuration file and set to cache
     #        else {
     // check file
     if (!file_exists($filename)) {
         throw new Days_Exception("Configuration file '{$filename}' not found");
     }
     // use fast Yaml module for php (if exists)
     if (function_exists('syck_load')) {
         $config = syck_load(file_get_contents($filename));
     } else {
         $config = Spyc::YAMLLoad($filename);
     }
     // renew cache
     #            $oCache->setCache($filename, $config);
     #        }
     // return result array
     return $config;
 }
Exemple #21
0
 /**
  * Gets all labels for a defined type.
  *
  * @param string $type   Name of the array group.
  * @param string $locale Locale code.
  *
  * @access public
  * @static
  * @uses   Config()
  * @uses   \Spyc
  *
  * @return array
  */
 public static function getAll($type, $locale = '')
 {
     if (!$locale) {
         $locale = Core\Registry()->get('locale');
     }
     return \Spyc::YAMLLoad(Core\Config()->paths('labels') . $locale . DIRECTORY_SEPARATOR . $type . '.yaml');
 }
 function imageTag($src, $alt = '', $options = array())
 {
     if (is_file($_SERVER['DOCUMENT_ROOT'] . $src)) {
         $file = $_SERVER['DOCUMENT_ROOT'] . $src;
     } else {
         if (is_file(BASE_DIR . $src)) {
             $file = BASE_DIR . $src;
         } else {
             return '';
         }
     }
     if (is_string($options)) {
         require_once 'vendor/spyc.php';
         $val = @Spyc::YAMLLoad($options);
         if (!empty($val)) {
             // it's a YAML array, so load it into options['update']
             $options = $val;
         }
     }
     $code = '';
     if (is_array($options)) {
         $options['style'] = 'border:0;' . (isset($options['style']) ? $options['style'] : '');
         foreach ($options as $key => $val) {
             $code .= " {$key}=\"{$val}\"";
         }
     } else {
         $code = ' style="border:0;" ' . $options;
     }
     $size = getImageSize($file);
     $src = (defined('EXTERNAL_CACHE') && constant('EXTERNAL_CACHE') ? EXTERNAL_CACHE : '') . $src;
     return '<img src="' . $src . '" alt="' . $alt . '" width="' . $size[0] . '" height="' . $size[1] . '"' . $code . ' />';
 }
 /**
  * Parse a block of YAML into PHP
  *
  * @param string  $yaml  YAML-formatted string to parse
  * @param string  $mode  Parsing mode to use
  * @return array
  */
 public static function parse($yaml, $mode = null)
 {
     // start measuring
     $hash = Debug::markStart('parsing', 'yaml');
     $mode = $mode ? $mode : self::getMode();
     switch ($mode) {
         case 'loose':
             $result = Spyc::YAMLLoad($yaml);
             break;
         case 'strict':
             $result = sYAML::parse($yaml);
             break;
         case 'transitional':
             try {
                 $result = sYaml::parse($yaml);
             } catch (Exception $e) {
                 Log::error($e->getMessage() . ' Falling back to loose mode.', 'core', 'yaml');
                 $result = Spyc::YAMLLoad($yaml);
             }
             break;
         default:
             // check for new lines, is this a file?
             $has_newline = strpos($yaml, "\n") !== false;
             if (!$has_newline && File::exists($yaml)) {
                 // seems like it is
                 $yaml = File::get($yaml);
             }
             $result = Statamic\Dipper\Dipper::parse($yaml);
     }
     // end measuring
     Debug::markEnd($hash);
     Debug::increment('parses', 'yaml');
     return $result;
 }
Exemple #24
0
 /**
  * Sets up some standard variables as well as starts the user agent parsing process
  *
  * @return {Object}       the result of the user agent parsing
  */
 public static function parse($ua = NULL)
 {
     self::$ua = $ua ? $ua : strip_tags($_SERVER["HTTP_USER_AGENT"]);
     self::$accept = empty($_SERVER["HTTP_ACCEPT"]) ? '' : strip_tags($_SERVER["HTTP_ACCEPT"]);
     if (empty(self::$regexes)) {
         if (file_exists(__DIR__ . "/resources/regexes.yaml")) {
             self::$regexes = Spyc::YAMLLoad(__DIR__ . "/resources/regexes.yaml");
         } else {
             print "<h1>Error</h1>\n\t\t\t\t\t   <p>Please download the regexes.yaml file before using UAParser.php.</p>\n\t\t\t\t\t   <p>You can type the following at the command line to download the latest version:</p>\n\t\t\t\t\t   <blockquote>\n\t\t\t\t\t\t<code>%: cd /path/to/UAParser</code><br />\n\t\t\t\t\t   \t<code>%: php UAParser.php -get</code>\n\t\t\t\t\t   </blockquote>";
             exit;
         }
     }
     // run the regexes to match things up
     $uaRegexes = self::$regexes['user_agent_parsers'];
     foreach ($uaRegexes as $uaRegex) {
         if ($result = self::uaParser($uaRegex)) {
             $result->uaOriginal = self::$ua;
             break;
         }
     }
     // if no browser was found check to see if it can be matched at least against a device (e.g. spider, generic feature phone or generic smartphone)
     if (!$result) {
         if (($result = self::deviceParser()) && $result->device != 'Spider') {
             $result->isMobile = true;
             $result->isMobileDevice = true;
             $result->uaOriginal = self::$ua;
         } else {
             if (isset($result) && isset($result->device) && $result->device == "Spider") {
                 $result->isMobile = false;
                 $result->isSpider = true;
                 $result->uaOriginal = self::$ua;
             }
         }
     }
     // still false?! see if it's a really dumb feature phone, if not just mark it as unknown
     if (!$result) {
         if (strpos(self::$accept, 'text/vnd.wap.wml') > 0 || strpos(self::$accept, 'application/vnd.wap.xhtml+xml') > 0 || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) {
             $result = new stdClass();
             $result->device = "Generic Feature Phone";
             $result->deviceFull = "Generic Feature Phone";
             $result->isMobile = true;
             $result->isMobileDevice = true;
             $result->uaOriginal = self::$ua;
         } else {
             $result = new stdClass();
             $result->device = "Unknown";
             $result->deviceFull = "Unknown";
             $result->isMobile = false;
             $result->isMobileDevice = false;
             $result->isComputer = true;
             $result->uaOriginal = self::$ua;
         }
     }
     // log the results when testing
     if (self::$debug) {
         self::log($result);
     }
     return $result;
 }
 public static function load_schema_from_yaml($table)
 {
     $schema = Spyc::YAMLLoad('db/' . $table . '.yaml');
     $sqlite = new sqlite();
     $pragma = $sqlite->query("PRAGMA table_info({$table})");
     foreach ($pragma as $k => $v) {
         $pragma_fields[] = $v->name;
     }
     // If pragma returns info, table exists, enter ALTER mode
     if (count($pragma) > 0) {
         echo "Table {$table} exists.\r\n";
         foreach ($schema as $k => $v) {
             if (in_array($v['name'], $pragma_fields)) {
                 echo 'Column ' . $v['name'] . " exists\r\n";
             } else {
                 echo $v['name'] . " does not exist\r\n";
                 if ($v['notnul'] == 1) {
                     $notnull = 'NOT NULL';
                 } else {
                     $notnull = 'NULL';
                 }
                 if ($v['default'] != '') {
                     $default = 'DEFAULT ' . $v['default'];
                 }
                 $sql = "ALTER TABLE {$table} ADD COLUMN " . $v['name'] . " " . $v['type'] . " {$notnull} " . $v['default'];
                 $sqlite->exec($sql);
                 echo $v['name'] . " column added\r\n";
             }
         }
         // pragma returns zero, enter CREATE TABLE mode
     } else {
         $sql = "create table {$table} (";
         foreach ($schema as $k => $v) {
             if ($v['notnul'] == 1) {
                 $notnull = 'NOT NULL';
             } else {
                 $notnull = 'NULL';
             }
             if ($v['default'] != '') {
                 $default = 'DEFAULT ' . $v['default'];
             }
             if ($v['isprimarykey'] == 0) {
                 $sql .= $v['name'] . " " . $v['type'] . " {$notnull} {$default},";
             } else {
                 $sql .= $v['name'] . " " . $v['type'] . " PRIMARY KEY,";
             }
         }
         // Trim trailing comma and close statement
         $sql = rtrim($sql, ",");
         $sql .= ")";
         echo "{$sql} \r\n";
         $sqlite->exec($sql);
         echo "Table {$table} created.\r\n";
     }
     // SQL create table syntax cheatsheet
     // Primary key: FIELDNAME INTEGER PRIMARY KEY
     // Fields:      FIELDNAME  TYPE(LENGTH) NULL DEFAULT ''
     // Timestamp:   timestamp DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
 }
Exemple #26
0
function run_micro($workdir)
{
    $info = Spyc::YAMLLoad("{$workdir}/info.yaml");
    $jobid = basename("{$workdir}");
    $BASE = $info['BASE'];
    $species = $info['species'];
    $species2 = $info['species2'];
    $allfile = unserialize($info['allfile']);
    $tags = unserialize($info['tags']);
    $selectfile = unserialize($info['selectfile']);
    $hash = array();
    $total = array();
    $i = 0;
    $key = 1;
    foreach ($allfile as $aa) {
        if (file_exists("{$BASE}/upload/{$aa}")) {
            $fp = fopen("{$BASE}/upload/{$aa}", 'r');
            while (!feof($fp)) {
                $line = chop(fgets($fp));
                if (preg_match("/\\>seq/", $line)) {
                    $ss = explode("_x", $line);
                    $seq = chop(fgets($fp));
                    $hash[$tags["{$i}"]][$seq] = $ss[1] + 0;
                    $total[$seq]['name'] = "seq_" . $key . "_len_" . strlen($seq);
                    $total[$seq]['count'] = 0;
                    $key++;
                }
            }
        }
        $i++;
    }
    $fd = fopen("{$workdir}/totalreads.fa", "w") or die("Can't open {$filename}");
    foreach ($total as $key => $value) {
        $fout = fwrite($fd, ">" . $total[$key]['name'] . "\n");
        $fout = fwrite($fd, $key . "\n");
    }
    fclose($fd);
    $fd = fopen("{$workdir}/allcounts", "w") or die("Can't open {$filename}");
    $fout = fwrite($fd, "X\t");
    foreach ($tags as $key => $value) {
        $fout = fwrite($fd, $tags[$key] . "\t");
    }
    $fout = fwrite($fd, "All\n");
    foreach ($total as $key2 => $value2) {
        $fout = fwrite($fd, $total[$key2]['name'] . "\t");
        foreach ($tags as $key => $value) {
            if ($hash[$value][$key2]) {
                $fout = fwrite($fd, $hash[$value][$key2] . "\t");
                $total[$key2]['count'] = $total[$key2]['count'] + $hash[$value][$key2];
            } else {
                $fout = fwrite($fd, "0\t");
            }
        }
        $fout = fwrite($fd, $total[$key2]['count']);
        $fout = fwrite($fd, "\n");
    }
    fclose($fd);
    system("cd {$workdir}\n\n{$BASE}/tools/run.pl -i {$workdir}/*.fq -o {$workdir} -a {$species2} -s {$species}");
}
/**
 * Plugin Load Config
 * Load a plugins' YAML config file.
 *
 * @since 1.0.0
 *
 * $plugin: (string) name of the plugin to load
 */
function plugin_load_config($plugin)
{
    $config = Spyc::YAMLLoad(ROOT_DIR . '/_plugins/' . $plugin . '/.config.yml');
    if (extras_enabled()) {
        $config = apply_filters($plugin . '_load_config', $config);
    }
    return $config;
}
 /**
  * Load Language
  */
 protected function loadLanguage()
 {
     if (file_exists($language = ROOT . '/' . 'lang' . '/' . static::$site['backend_language'] . '.yml')) {
         static::$lang = Spyc::YAMLLoad(file_get_contents($language));
     } else {
         die("Oops.. Where is language file ?!");
     }
 }
Exemple #29
0
 function load($file)
 {
     if (!file_exists($file)) {
         raise_error("{$file}: File does not exist", 'YamlParserError');
         return false;
     }
     return Spyc::YAMLLoad($file);
 }
Exemple #30
0
 /**
  * Loads in and parses the given Yaml file
  * 
  * @param   string  $string  the yaml file to parse
  * @return  array   the parsed yaml array
  */
 public function parse_file($file)
 {
     if (!is_file($file)) {
         show_error('Yaml - Trying to parse an invalid file: ' . $file);
     }
     $file = file_get_contents($file);
     return Spyc::YAMLLoad($file);
 }