/** * Filters an asset after it has been loaded. * * @param \Assetic\Asset\AssetInterface $asset * @return void */ public function filterLoad(AssetInterface $asset) { $max_nesting_level = ini_get('xdebug.max_nesting_level'); $memory_limit = ini_get('memory_limit'); if ($max_nesting_level && $max_nesting_level < 200) { ini_set('xdebug.max_nesting_level', 200); } if ($memory_limit && $memory_limit < 256) { ini_set('memory_limit', '256M'); } $root = $asset->getSourceRoot(); $path = $asset->getSourcePath(); $dirs = array(); $lc = new \Less_Parser(array('compress' => true)); if ($root && $path) { $dirs[] = dirname($root . '/' . $path); } foreach ($this->loadPaths as $loadPath) { $dirs[] = $loadPath; } $lc->SetImportDirs($dirs); $url = parse_url($this->getRequest()->getUriForPath('')); $absolutePath = str_replace(public_path(), '', $root); if (isset($url['path'])) { $absolutePath = $url['path'] . $absolutePath; } $lc->parseFile($root . '/' . $path, $absolutePath); $asset->setContent($lc->getCss()); }
/** * Compiles a template and writes it to a cache file, which is used for inclusion. * * @param string $file The full path to the template that will be compiled. * @param array $options Options for compilation include: * - `path`: Path where the compiled template should be written. * - `fallback`: Boolean indicating that if the compilation failed for some * reason (e.g. `path` is not writable), that the compiled template * should still be returned and no exception be thrown. * @return string The compiled template. */ public static function template($file, array $options = array()) { $cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates'; $defaults = array('path' => $cachePath, 'fallback' => false); $options += $defaults; $stats = stat($file); $oname = basename(dirname($file)) . '_' . basename($file, '.php'); $oname .= '_' . ($stats['ino'] ?: hash('md5', $file)); $template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php"; $template = "{$options['path']}/{$template}"; if (file_exists($template)) { return $template; } $compiled = static::compile(file_get_contents($file)); if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) { foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) { if ($expired !== $template) { unlink($expired); } } return $template; } if ($options['fallback']) { return $file; } throw new TemplateException("Could not write compiled template `{$template}` to cache."); }
function command_dd() { $args = func_get_args(); $options = $this->get_options(); $dd = kernel::single('dev_docbuilder_dd'); if (empty($args)) { $dd->export(); } else { foreach ($args as $app_id) { $dd->export_tables($app_id); } } if ($filename = $options['result-file']) { ob_start(); $dd->output(); $out = ob_get_contents(); ob_end_clean(); if (!is_dir(dirname($filename))) { throw new Exception('cannot find the ' . dirname($filename) . 'directory'); } elseif (is_dir($filename)) { throw new Exception('the result-file path is a directory.'); } file_put_contents($options['result-file'], $out); echo 'data dictionary doc export success.'; } else { $dd->output(); } }
/** * * @param array $current_import * @return bool */ function import(array $current_import) { // fetch the remote content $html = wp_remote_get($current_import['file']); // Something failed if (is_wp_error($html)) { $redirect_url = get_admin_url(get_current_blog_id(), '/tools.php?page=pb_import'); error_log('\\PressBooks\\Import\\Html import error, wp_remote_get() ' . $html->get_error_message()); $_SESSION['pb_errors'][] = $html->get_error_message(); $this->revokeCurrentImport(); \Pressbooks\Redirect\location($redirect_url); } $url = parse_url($current_import['file']); // get parent directory (with forward slash e.g. /parent) $path = dirname($url['path']); $domain = $url['scheme'] . '://' . $url['host'] . $path; // get id (there will be only one) $id = array_keys($current_import['chapters']); // front-matter, chapter, or back-matter $post_type = $this->determinePostType($id[0]); $chapter_parent = $this->getChapterParent(); $body = $this->kneadandInsert($html['body'], $post_type, $chapter_parent, $domain); // Done return $this->revokeCurrentImport(); }
public function setUp() { $_SERVER['REDIRECT_STATUS'] = "200"; $_SERVER['HTTP_HOST'] = "slim"; $_SERVER['HTTP_CONNECTION'] = "keep-alive"; $_SERVER['HTTP_CACHE_CONTROL'] = "max-age=0"; $_SERVER['HTTP_ACCEPT'] = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $_SERVER['HTTP_USER_AGENT'] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3"; $_SERVER['HTTP_ACCEPT_ENCODING'] = "gzip,deflate,sdch"; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en-US,en;q=0.8"; $_SERVER['HTTP_ACCEPT_CHARSET'] = "ISO-8859-1,utf-8;q=0.7,*;q=0.3"; $_SERVER['PATH'] = "/usr/bin:/bin:/usr/sbin:/sbin"; $_SERVER['SERVER_SIGNATURE'] = ""; $_SERVER['SERVER_SOFTWARE'] = "Apache"; $_SERVER['SERVER_NAME'] = "slim"; $_SERVER['SERVER_ADDR'] = "127.0.0.1"; $_SERVER['SERVER_PORT'] = "80"; $_SERVER['REMOTE_ADDR'] = "127.0.0.1"; $_SERVER['DOCUMENT_ROOT'] = rtrim(dirname(__FILE__), '/'); $_SERVER['SERVER_ADMIN'] = "*****@*****.**"; $_SERVER['SCRIPT_FILENAME'] = __FILE__; $_SERVER['REMOTE_PORT'] = "55426"; $_SERVER['REDIRECT_URL'] = "/"; $_SERVER['GATEWAY_INTERFACE'] = "CGI/1.1"; $_SERVER['SERVER_PROTOCOL'] = "HTTP/1.1"; $_SERVER['REQUEST_METHOD'] = "GET"; $_SERVER['QUERY_STRING'] = ""; $_SERVER['REQUEST_URI'] = "/"; $_SERVER['SCRIPT_NAME'] = basename(__FILE__); $_SERVER['PHP_SELF'] = '/' . basename(__FILE__); $_SERVER['REQUEST_TIME'] = "1285647051"; $_SERVER['argv'] = array(); $_SERVER['argc'] = 0; }
function __construct() { $this->_logDir = dirname(__FILE__) . "/../logs"; if (!file_exists($this->_logDir)) { mkdir($this->_logDir, 0777, true); } }
protected function rmFile($file) { if (is_file($file)) { chmod(dirname($file), 0777); unlink($file); } }
protected function createPath() { $fullPath = dirname($this->fullFilePath()); if (!is_dir($fullPath)) { mkdir($fullPath, 0755, true); } }
public function imitateLogin($sdutnum, $password) { //模拟登录 $cookie_jar = dirname(__FILE__) . "/cookie"; $urlLogin = "******"; $post = "number={$sdutnum}&passwd={$password}&select=cert_no&returnUrl="; $this->curl->login_post($urlLogin, $cookie_jar, $post); //抓取内容 $urlBook = "http://222.206.65.12/reader/book_lst.php"; $html = $this->curl->get_content($urlBook, $cookie_jar); $loginReg = "/logout/"; $BookReg = "/<td.*/"; $buttonReg = "/<div\\sid=\"\\w\"><input.*\\/>/"; $nameReg = '/height="11" \\/>.*logout/'; $numReg = '/<p>.*<b/'; //book number preg_match_all($loginReg, $html, $isLogin); //to judgment whether login preg_match_all($BookReg, $html, $bookArray); preg_match_all($buttonReg, $html, $buttonArray); preg_match_all($nameReg, $html, $nameArray); //username preg_match_all($numReg, $html, $numArray); empty($nameArray[0]) ? $username = null : ($username = substr($nameArray[0][0], 14, -37)); empty($numArray[0]) ? $bookNum = null : ($bookNum = substr($numArray[0][0], 45, -25)); $bookData['sdutnum'] = $sdutnum; /* after changed session*/ $bookData['isLogin'] = $isLogin; $bookData['bookArray'] = $bookArray; $bookData['buttonArray'] = $buttonArray; $bookData['username'] = $username; $bookData['numArray'] = $numArray; $bookData['bookNum'] = $bookNum; return $bookData; }
/** * {@inheritDoc} */ public function initialize() { if (Filesystem::isLocalPath($this->url)) { $this->repoDir = $this->url; } else { $cacheDir = $this->config->get('cache-vcs-dir'); $this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/'; $fs = new Filesystem(); $fs->ensureDirectoryExists($cacheDir); if (!is_writable(dirname($this->repoDir))) { throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $cacheDir . '" directory is not writable by the current user.'); } // update the repo if it is a valid hg repository if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) { if (0 !== $this->process->execute('hg pull', $output, $this->repoDir)) { $this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>'); } } else { // clean up directory and do a fresh clone into it $fs->removeDirectory($this->repoDir); if (0 !== $this->process->execute(sprintf('hg clone --noupdate %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoDir)), $output, $cacheDir)) { $output = $this->process->getErrorOutput(); if (0 !== $this->process->execute('hg --version', $ignoredOutput)) { throw new \RuntimeException('Failed to clone ' . $this->url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput()); } throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output); } } } $this->getTags(); $this->getBranches(); }
public function __construct($name = null, array $data = array(), $dataName = '') { $this->_className = $name; $this->_root = dirname(__FILE__); date_default_timezone_set('UTC'); parent::__construct($name, $data, $dataName); }
protected function initInternal() { parent::initInternal(); // override default xml $this->ui = new AdminUI(); $this->ui->loadFromXML(dirname(__FILE__) . '/time.xml'); }
function _moduleContent(&$smarty, $module_name) { include_once "modules/{$module_name}/configs/default.conf.php"; load_language_module($module_name); global $arrConf; global $arrConfModule; $arrConf = array_merge($arrConf, $arrConfModule); //folder path for custom templates $base_dir = dirname($_SERVER['SCRIPT_FILENAME']); $templates_dir = isset($arrConf['templates_dir']) ? $arrConf['templates_dir'] : 'themes'; $local_templates_dir = "{$base_dir}/modules/{$module_name}/" . $templates_dir . '/' . $arrConf['theme']; $sContenidoModulo = ''; $sAccion = getParameter('action'); switch ($sAccion) { case 'new': case 'edit': $sContenidoModulo = modificarArchivo($module_name, $smarty, $local_templates_dir, $arrConf['astetcdir'], $sAccion); break; case 'list': default: $sContenidoModulo = listarArchivos($module_name, $smarty, $local_templates_dir, $arrConf['astetcdir']); break; } return $sContenidoModulo; }
/** * Initializes this logger. * * Available options: * * - file: The file path or a php wrapper to log messages * You can use any support php wrapper. To write logs to the Apache error log, use php://stderr * - format: The log line format (default to %time% %type% [%priority%] %message%%EOL%) * - time_format: The log time strftime format (default to %b %d %H:%M:%S) * - dir_mode: The mode to use when creating a directory (default to 0777) * - file_mode: The mode to use when creating a file (default to 0666) * * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options An array of options. * * @return Boolean true, if initialization completes successfully, otherwise false. */ public function initialize(sfEventDispatcher $dispatcher, $options = array()) { if (!isset($options['file'])) { throw new sfConfigurationException('You must provide a "file" parameter for this logger.'); } if (isset($options['format'])) { $this->format = $options['format']; } if (isset($options['time_format'])) { $this->timeFormat = $options['time_format']; } if (isset($options['type'])) { $this->type = $options['type']; } $dir = dirname($options['file']); if (!is_dir($dir)) { mkdir($dir, isset($options['dir_mode']) ? $options['dir_mode'] : 0777, true); } $fileExists = file_exists($options['file']); if (!is_writable($dir) || $fileExists && !is_writable($options['file'])) { throw new sfFileException(sprintf('Unable to open the log file "%s" for writing.', $options['file'])); } $this->fp = fopen($options['file'], 'a'); if (!$fileExists) { chmod($options['file'], isset($options['file_mode']) ? $options['file_mode'] : 0666); } return parent::initialize($dispatcher, $options); }
function test_get_item_uris() { $snapshots = new Snapshots(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'documents/snapshots.rdf'); $expected = array("http://api.talis.com/stores/schema-cache/snapshots/20071129173353.tar"); $actual = $snapshots->get_item_uris(); $this->assertEquals($expected, $actual); }
/** * @ORM\PreFlush() */ public function preUpload() { if ($this->file) { if ($this->file instanceof FileUpload) { $basename = $this->file->getSanitizedName(); $basename = $this->suggestName($this->getFilePath(), $basename); $this->setName($basename); } else { $basename = trim(Strings::webalize($this->file->getBasename(), '.', FALSE), '.-'); $basename = $this->suggestName(dirname($this->file->getPathname()), $basename); $this->setName($basename); } if ($this->_oldPath && $this->_oldPath !== $this->path) { @unlink($this->getFilePathBy($this->_oldProtected, $this->_oldPath)); } if ($this->file instanceof FileUpload) { $this->file->move($this->getFilePath()); } else { copy($this->file->getPathname(), $this->getFilePath()); } return $this->file = NULL; } if (($this->_oldPath || $this->_oldProtected !== NULL) && ($this->_oldPath != $this->path || $this->_oldProtected != $this->protected)) { $oldFilePath = $this->getFilePathBy($this->_oldProtected !== NULL ? $this->_oldProtected : $this->protected, $this->_oldPath ?: $this->path); if (file_exists($oldFilePath)) { rename($oldFilePath, $this->getFilePath()); } } }
/** * Returns an array of all possible upgrade files as an array with * the upgrade's key and version * * This first looks for all .php files in the versions directory. * The files should have the format of VERSION_NUMBER (e.g. 1.0.0__1). * The project is then checked to see if */ public function getUpgrades() { if (!$this->_upgrades) { $this->_upgrades = array(); $versions = array(); $dir = dirname(__FILE__) . '/versions'; $files = sfFinder::type('file')->name('*.php')->in($dir); foreach ($files as $file) { $info = pathinfo($file); if (strpos($info['filename'], '__') === false) { throw new sfException(sprintf('Invalid upgrade filename format for file "%s" - must contain a double underscore - VERSION__NUMBER (e.g. 1.0.0__1) ', $info['filename'])); } $e = explode('__', $info['filename']); $version = $e[0]; $number = $e[1]; if ($this->_isVersionNew($info['filename'])) { $versions[] = array('version' => $version, 'number' => $number); $this->_upgrades[] = $version . '__' . $number; } } natcasesort($this->_upgrades); foreach ($this->_upgrades as $key => $version) { $this->_upgrades[$key] = $versions[$key]; } } return $this->_upgrades; }
/** * Assert that commands depending on unknown commandfiles are detected. */ public function testMissingDrushDependency() { $options = array('include' => dirname(__FILE__), 'backend' => NULL); $this->drush('unit-drush-dependency', array(), $options, NULL, NULL, self::EXIT_ERROR); $parsed = parse_backend_output($this->getOutput()); $this->assertArrayHasKey("DRUSH_COMMANDFILE_DEPENDENCY_ERROR", $parsed['error_log']); }
/** * Singleton Constructor */ private function __construct() { // Registro em Autocarregamento spl_autoload_register(array($this, 'load')); // Configuração de Mapeamento $this->setMapper('Pokeflute', dirname(__FILE__))->setMapper('Model', APPLICATION_PATH . '/models'); }
function cherry_plugin_settings() { global $wpdb; if (!function_exists('get_plugin_data')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $upload_dir = wp_upload_dir(); $plugin_data = get_plugin_data(plugin_dir_path(__FILE__) . 'cherry-plugin.php'); //Cherry plugin constant variables define('CHERRY_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('CHERRY_PLUGIN_URL', plugin_dir_url(__FILE__)); define('CHERRY_PLUGIN_DOMAIN', $plugin_data['TextDomain']); define('CHERRY_PLUGIN_DOMAIN_DIR', $plugin_data['DomainPath']); define('CHERRY_PLUGIN_VERSION', $plugin_data['Version']); define('CHERRY_PLUGIN_NAME', $plugin_data['Name']); define('CHERRY_PLUGIN_SLUG', plugin_basename(__FILE__)); define('CHERRY_PLUGIN_DB', $wpdb->prefix . CHERRY_PLUGIN_DOMAIN); define('CHERRY_PLUGIN_REMOTE_SERVER', esc_url('http://tmbhtest.com/cherryframework.com/components_update/')); //Other constant variables define('CURRENT_THEME_DIR', get_stylesheet_directory()); define('CURRENT_THEME_URI', get_stylesheet_directory_uri()); define('UPLOAD_BASE_DIR', str_replace("\\", "/", $upload_dir['basedir'])); define('UPLOAD_DIR', str_replace("\\", "/", $upload_dir['path'] . '/')); // if ( !defined('API_URL') ) { // define( 'API_URL', esc_url( 'http://updates.cherry.template-help.com/cherrymoto/v3/api/' ) ); // } load_plugin_textdomain(CHERRY_PLUGIN_DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/' . CHERRY_PLUGIN_DOMAIN_DIR); do_action('cherry_plugin_settings'); }
function __construct(array $config = array()) { $this->_config =& $config; // Try to locate app folder. if (!isset($config['app_dir'])) { $cwd = getcwd(); while (!is_dir("{$cwd}/app")) { if ($cwd == dirname($cwd)) { throw new \LogicException('/app folder not found.'); } $cwd = dirname($cwd); } $config['app_dir'] = "{$cwd}/app"; } $is_web_request = isset($_SERVER['SERVER_NAME']); $config += array('debug' => !$is_web_request || $_SERVER['SERVER_NAME'] == 'localhost', 'register_exception_handler' => $is_web_request, 'register_error_handler' => $is_web_request, 'core_dir' => __DIR__ . '/../..', 'data_dir' => "{$config['app_dir']}/../data"); $this->exception_handler = new ExceptionHandler($this->debug); if ($this->register_exception_handler) { set_exception_handler(array($this->exception_handler, 'handle')); } if ($this->register_error_handler) { $this->errorHandler = \Symfony\Component\HttpKernel\Debug\ErrorHandler::register(); } foreach (array($config['data_dir'], "{$config['data_dir']}/cache", "{$config['data_dir']}/logs") as $dir) { if (!is_dir($dir)) { mkdir($dir); } } }
public static function prepare_dir($prefix) { $config = midcom_baseclasses_components_configuration::get('midcom.helper.filesync', 'config'); $path = $config->get('filesync_path'); if (!file_exists($path)) { $parent = dirname($path); if (!is_writable($parent)) { throw new midcom_error("Directory {$parent} is not writable"); } if (!mkdir($path)) { throw new midcom_error("Failed to create directory {$path}. Reason: " . $php_errormsg); } } if (substr($path, -1) != '/') { $path .= '/'; } $module_dir = "{$path}{$prefix}"; if (!file_exists($module_dir)) { if (!is_writable($path)) { throw new midcom_error("Directory {$path} is not writable"); } if (!mkdir($module_dir)) { throw new midcom_error("Failed to create directory {$module_dir}. Reason: " . $php_errormsg); } } return "{$module_dir}/"; }
public function actionIndex() { if (isset($_GET['id'])) { $model = Document::model()->findByPk($_GET['id']); $this->render('detail', array('model' => $model)); $cfg = (require dirname(__FILE__) . '/../../config/main.php'); //print '<pre>'; //print_r($cfg['components']['db']); if (preg_match("/^mysql:host=(\\w.*);dbname=(\\w.*)/i", $cfg['components']['db']['connectionString'], $match)) { //print_r($match); } //$db_name = "myphotos"; //$db_server = "localhost"; //$db_user = "******"; //$db_pass = ""; $db_name = $match[2]; $db_server = $match[1]; $db_user = $cfg['components']['db']["username"]; $db_pass = $cfg['components']['db']["password"]; $sql = "UPDATE gs_document SET counter=counter+1 WHERE doc_id='" . $_GET['id'] . "'"; //print $sql; //$command = Yii::app()->db->createCommand($sql); //$command->execute(); $dbh = new PDO('mysql:host=' . $db_server . ';port=3306;dbname=' . $db_name, $db_user, $db_pass, array(PDO::ATTR_PERSISTENT => false)); $stmt = $dbh->prepare($sql); $stmt->execute(); } else { $criteria = new CDbCriteria(); $criteria->select = '*'; $criteria->condition = 'status = 1'; $criteria->order = 'sort_order ASC ,last_update DESC'; $model = Document::model()->findAll($criteria); $this->render('index', array('model' => $model)); } }
/** * Sets data * * @param string $key * @param string $var * @param int $expire * @return boolean */ function set($key, $var, $expire = 0) { $key = $this->get_item_key($key); $sub_path = $this->_get_path($key); $path = $this->_cache_dir . '/' . $sub_path; $sub_dir = dirname($sub_path); $dir = dirname($path); if (!@is_dir($dir)) { if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) { return false; } } $fp = @fopen($path, 'w'); if (!$fp) { return false; } if ($this->_locking) { @flock($fp, LOCK_EX); } @fputs($fp, $var['content']); @fclose($fp); if ($this->_locking) { @flock($fp, LOCK_UN); } // some hostings create files with restrictive permissions // not allowing apache to read it later @chmod($path, 0644); $old_entry_path = $path . '.old'; @unlink($old_entry_path); if (w3_is_apache() && isset($var['headers']) && isset($var['headers']['Content-Type']) && substr($var['headers']['Content-Type'], 0, 8) == 'text/xml') { file_put_contents(dirname($path) . '/.htaccess', "<IfModule mod_mime.c>\n" . " RemoveType .html_gzip\n" . " AddType text/xml .html_gzip\n" . " RemoveType .html\n" . " AddType text/xml .html\n" . "</IfModule>"); } return true; }
/** * Config */ public function __construct() { $posts = json_decode(file_get_contents(dirname(__FILE__) . '/posts.json'), true); foreach ($posts as $key => $post) { $this->posts[$key] = (object) $post; } }
/** * @inheritdoc */ protected function bootstrap() { $request = $this->getRequest(); Yii::setAlias('@webroot', dirname($request->getScriptFile())); Yii::setAlias('@web', $request->getBaseUrl()); parent::bootstrap(); }
/** * Defines tests for this suite * * @return CakeTestSuite The test suite. */ public static function suite() { $Suite = new CakeTestSuite('All Controller tests'); $path = dirname(__FILE__); $Suite->addTestDirectory($path . DS . 'Controller'); return $Suite; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { require_once dirname(__FILE__) . '/sfLimeHarness.class.php'; $h = new sfLimeHarness(array('force_colors' => isset($options['color']) && $options['color'], 'verbose' => isset($options['trace']) && $options['trace'])); $h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins())); $h->base_dir = sfConfig::get('sf_test_dir'); $status = false; $statusFile = sfConfig::get('sf_cache_dir') . '/.test_all_status'; if ($options['only-failed']) { if (file_exists($statusFile)) { $status = unserialize(file_get_contents($statusFile)); } } if ($status) { foreach ($status as $file) { $h->register($file); } } else { // filter and register all tests $finder = sfFinder::type('file')->follow_link()->name('*Test.php'); $h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options)); } $ret = $h->run() ? 0 : 1; file_put_contents($statusFile, serialize($h->get_failed_files())); if ($options['xml']) { file_put_contents($options['xml'], $h->to_xml()); } return $ret; }
/** * Make API request * * @param string $method string API method to request * @param array $params Additional request parameters * @return array / boolean Response array / boolean false on failure */ public function request($method, $params = array()) { $this->_errors = array(); if (empty($method)) { //Check if API method is not empty $this->_errors = array('API method is missing'); return false; } //Our request parameters $requestParams = array('METHOD' => $method, 'VERSION' => $this->_version) + $this->_credentials; //Building our NVP string $request = http_build_query($requestParams + $params); //cURL settings $curlOptions = array(CURLOPT_URL => $this->_endPoint, CURLOPT_VERBOSE => 1, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem', CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $request); $ch = curl_init(); curl_setopt_array($ch, $curlOptions); //Sending our request - $response will hold the API response $response = curl_exec($ch); //Checking for cURL errors if (curl_errno($ch)) { $this->_errors = curl_error($ch); curl_close($ch); return false; //Handle errors } else { curl_close($ch); $responseArray = array(); parse_str($response, $responseArray); // Break the NVP string to an array return $responseArray; } }
protected function __construct($config) { if (count($config["db"]) != 4) { throw new \Exception("Le nombre d'arguments n'est pas valable!"); } spl_autoload_register(array(__CLASS__, 'autoload')); self::$config = $config; self::$database = new Core\Db\ConnectPDO(self::$config["db"]); self::$baseUrl = rtrim(dirname($_SERVER['PHP_SELF']), '/.\\'); $route = isset($_GET["r"]) ? $_GET["r"] : $_SERVER["REQUEST_URI"]; $url = parse_url($route); $path = preg_replace('/^' . preg_quote(self::$baseUrl, '/') . '\\//', "", $url["path"]); $query = @$url["query"]; $method = $_SERVER['REQUEST_METHOD']; $request = new Core\Http\Request($method, $path, $query); $dispatcher = new Core\Http\Dispatcher(); try { $dispatcher->handle($request); } catch (Exception $e) { $code = '404'; header($_SERVER["SERVER_PROTOCOL"] . " " . $code); $request = new Core\Http\Request('GET', 'Site/error', 'code=' . $code . '&message=' . $e->getMessage()); $dispatcher->handle($request); } }