/** * Send status updates to any relevant third parties (i.e. Github) */ public function sendStatusPostback() { $token = \b8\Config::getInstance()->get('phpci.github.token'); if (empty($token)) { return; } $project = $this->getProject(); $url = 'https://api.github.com/repos/' . $project->getReference() . '/statuses/' . $this->getCommitId(); $http = new \b8\HttpClient(); switch ($this->getStatus()) { case 0: case 1: $status = 'pending'; break; case 2: $status = 'success'; break; case 3: $status = 'failure'; break; default: $status = 'error'; break; } $phpciUrl = \b8\Config::getInstance()->get('phpci.url'); $params = array('state' => $status, 'target_url' => $phpciUrl . '/build/view/' . $this->getId()); $headers = array('Authorization: token ' . $token, 'Content-Type: application/x-www-form-urlencoded'); $http->setHeaders($headers); $http->request('POST', $url, json_encode($params)); }
protected function init() { if (empty($this->blobProxy)) { $config = Config::getInstance()->get('Octo.Azure.BlobStorage'); $this->blobProxy = ServicesBuilder::getInstance()->createBlobService($config['ConnectionString']); } }
protected function onPreRender(&$view) { /** @var \Octo\AssetManager $assets */ $assets = Config::getInstance()->get('Octo.AssetManager'); $assets->addExternalJs('//cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.3.2/jquery.payment.min.js'); parent::onPreRender($view); }
protected function getAssetCode() { /** @var \b8\Config */ $config = Config::getInstance(); $paths = $config->get('Octo.paths.modules'); /** @var \Octo\AssetManager $assets */ $assets = $config->get('Octo.AssetManager'); $inject = ['css' => '', 'js' => '']; foreach ($assets->getCss() as $css) { $path = $paths[$css['module']] . 'Public/css/' . $css['name'] . '.css'; if (is_file($path)) { $href = $config->get('site.url') . '/asset/css/' . $css['module'] . '/' . $css['name'] . '?t=' . filemtime($path); $inject['css'] .= '<link rel="stylesheet" type="text/css" href="' . $href . '">'; } } foreach ($assets->getExternalJs() as $js) { $inject['js'] .= '<script src="' . $js . '"></script>'; } foreach ($assets->getJs() as $js) { $path = $paths[$js['module']] . 'Public/js/' . $js['name'] . '.js'; if (is_file($path)) { $href = $config->get('site.url') . '/asset/js/' . $js['module'] . '/' . $js['name'] . '?t=' . filemtime($path); $inject['js'] .= '<script src="' . $href . '"></script>'; } } return $inject; }
/** * Get an array of repositories from Github's API. */ public function getRepositories() { $token = Config::getInstance()->get('phpci.github.token'); if (!$token) { die(json_encode(null)); } $cache = Cache::getCache(Cache::TYPE_APC); $rtn = $cache->get('phpci_github_repos'); if (!$rtn) { $orgs = $this->makeRequest('/user/orgs', array('access_token' => $token)); $params = array('type' => 'all', 'access_token' => $token); $repos = array('user' => array()); $repos['user'] = $this->makeRecursiveRequest('/user/repos', $params); foreach ($orgs as $org) { $repos[$org['login']] = $this->makeRecursiveRequest('/orgs/' . $org['login'] . '/repos', $params); } $rtn = array(); foreach ($repos as $repoGroup) { foreach ($repoGroup as $repo) { $rtn['repos'][] = $repo['full_name']; } } $cache->set('phpci_github_repos', $rtn); } return $rtn; }
/** * Checks if * @param $method * @param array $params * @return mixed|null */ public function __call($method, $params = array()) { unset($method, $params); $config = Config::getInstance(); $state = (bool) $config->get('phpci.authentication_settings.state', false); return false !== $state; }
protected function onPreRender(&$view) { parent::onPreRender($view); /** @var \Octo\AssetManager $assets */ $assets = Config::getInstance()->get('Octo.AssetManager'); $assets->addJs('Forms', 'phoneformat'); $view->type = 'tel'; }
protected function execute(InputInterface $input, OutputInterface $output) { if (!OCTO_QUEUE_ENABLED) { $error = 'The worker is not configured. You must set a worker host in your site config file.'; throw new \Exception($error); } $worker = new Worker(Config::getInstance()->get('Octo.worker.host')); $worker->run($input->getOption('verbose')); }
public static function exists($type) { $config = \b8\Config::getInstance(); $block = $config->get('Octo.namespaces.blocks.' . $type); if (!empty($block)) { return true; } return false; }
protected function getPath($module) { if ($module == 'site') { $siteNamespace = $this->config->get('site.namespace'); return APP_PATH . $siteNamespace . '/Public/'; } $paths = Config::getInstance()->get('Octo.paths.modules'); return $paths[$module] . 'Public/'; }
public function execute(InputInterface $input, OutputInterface $output) { unset($input, $output); $connection = Database::getConnection(); $namespaces = Config::getInstance()->get('app.namespaces'); $paths = Config::getInstance()->get('Octo.paths.namespaces'); $gen = new Database\CodeGenerator($connection, $namespaces, $paths, true); $gen->generateModels(); $gen->generateStores(); }
/** * @param $store * * @return \b8\Store; */ public function loadStore($store, $namespace = null) { if (!isset($this->loadedStores[$store])) { $namespace = is_null($namespace) ? Config::getInstance()->get('b8.app.namespace') : $namespace; $class = $namespace . '\\Store\\' . $store . 'Store'; $obj = new $class(); $this->loadedStores[$store] = $obj; } return $this->loadedStores[$store]; }
public function init() { $this->config = Config::getInstance(); $siteModules = array_reverse($this->config->get('ModuleManager')->getEnabled()); foreach ($siteModules as $namespace => $modules) { foreach ($modules as $module) { $path = $this->config->get('Octo.paths.modules.' . $module, '') . 'Event/'; $this->registerListeners($path, $namespace . '\\' . $module . '\\Event\\'); } } }
public function execute(InputInterface $input, OutputInterface $output) { unset($input, $output); $c = Config::getInstance(); $connection = Connection::get(); $namespaces = $c->get('app.namespaces'); $paths = $c->get('Octo.paths.namespaces'); $mapper = new Mapper($connection); $gen = new CodeGenerator($mapper, $namespaces, $paths); $gen->generateModels(); $gen->generateStores(); }
/** * Setup the menus for each controller */ protected function setupControllerMenus() { $this->config = Config::getInstance(); $paths = Config::getInstance()->get('Octo.paths.namespaces'); foreach ($paths as $namespace => $path) { $thisPath = $path . 'Admin/Controller/*.php'; $files = glob($thisPath); foreach ($files as $file) { $this->getControllerMenuItems($file, $namespace); } } }
public function img($module) { $parts = array_slice(func_get_args(), 1); $name = implode('/', $parts); $paths = Config::getInstance()->get('Octo.paths.modules'); $path = $paths[$module] . 'Public/img/' . $name; if (!file_exists($path)) { throw new NotFoundException('Asset ' . $module . '::' . $name . ' does not exist.'); } $this->response->disableLayout(); return file_get_contents($path); }
public static function delete(Job $job) { if ($job->getQueueId()) { $pheanstalk = new Pheanstalk(Config::getInstance()->get('Octo.worker.host')); try { $beanstalkJob = $pheanstalk->peek($job->getQueueId()); $pheanstalk->delete($beanstalkJob); } catch (\Exception $ex) { // Job is not in beanstalk. } } self::getStore()->delete($job); }
public static function getClass($controller) { $config = Config::getInstance(); $siteModules = $config->get('ModuleManager')->getEnabled(); foreach ($siteModules as $namespace => $modules) { foreach ($modules as $module) { $class = "\\{$namespace}\\{$module}\\Controller\\{$controller}Controller"; if (class_exists($class)) { return $class; } } } return null; }
public function getValue() { if (array_key_exists($this->getName(), $_FILES)) { $extension = substr($_FILES[$this->getName()]['name'], strrpos($_FILES[$this->getName()]['name'], '.')); $filename = '/uploads/' . md5(file_get_contents($_FILES[$this->getName()]['tmp_name'])) . $extension; $path = APP_PATH . 'public' . $filename; move_uploaded_file($_FILES[$this->getName()]['tmp_name'], $path); $url = Config::getInstance()->get('site.url') . $filename; $this->uploadedName = $_FILES[$this->getName()]['name']; $this->uploadedPath = $path; return $url; } return null; }
public static function getPath($template, $module = null) { $config = Config::getInstance(); $paths = array_reverse($config->get('Octo.paths.' . static::$templateType, [])); foreach ($paths as $moduleName => $path) { if (!is_null($module) && $moduleName !== $module) { $path .= $module . '/'; } if (file_exists($path . $template . '.html')) { return $path; } } return null; }
public function run() { $data = $this->job->getData(); $config = Config::getInstance(); $mail = new \PHPMailer(); // Enable SMTP if required: if (isset($config->site['smtp_server'])) { $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = $config->get('site.smtp_server', null); $mail->Username = $config->get('site.smtp_username', null); $mail->Password = $config->get('site.smtp_password', null); } // Is this email a HTML email? $mail->IsHTML(false); if (!empty($data['html']) && $data['html']) { $mail->IsHTML(true); } $mail->Subject = $data['subject']; $mail->CharSet = "UTF-8"; // Handle recipients and CCs: foreach ($data['to'] as $recipient) { $mail->addAddress($recipient['email'], $recipient['name']); } if (isset($data['cc']) && is_array($data['cc'])) { foreach ($data['cc'] as $recipient) { $mail->addCc($recipient['email'], $recipient['name']); } } // Handle Reply To: if (isset($data['reply_to']) && is_array($data['reply_to'])) { $mail->addReplyTo($data['reply_to']['email'], $data['reply_to']['name']); } // Handle From: if (isset($config->site['email_from'])) { $mail->SetFrom($config->site['email_from'], $config->site['email_from_name']); } // Handle attachments: if (isset($data['attachments']) && is_array($data['attachments'])) { foreach ($data['attachments'] as $name => $path) { $mail->addAttachment($path, $name); } } $mail->Body = $data['body']; if (!$mail->send()) { throw new Exception($mail->ErrorInfo); } return true; }
public static function registerMenus(Menu $menu) { /** @var \Octo\AssetManager $assets */ $assets = Config::getInstance()->get('Octo.AssetManager'); $assets->addJs('System', 'contact'); $thisMenu = $menu->addRoot('Contacts', '/contact')->setIcon('users'); $thisMenu->addChild(new Menu\Item('Add Contact', '/contact/add')); $thisMenu->addChild(new Menu\Item('Contact Popup', '/contact/popup', true)); $thisMenu->addChild(new Menu\Item('Manage Contacts', '/contact')); $thisMenu->addChild(new Menu\Item('Edit Contact', '/contact/edit', true)); $thisMenu->addChild(new Menu\Item('Contact Autocomplete', '/contact/autocomplete', true)); $thisMenu->addChild(new Menu\Item('Contact Autocomplete', '/contact/autocomplete', true)); $thisMenu->addChild(new Menu\Item('Block Contact', '/contact/block', true)); $thisMenu->addChild(new Menu\Item('Unblock Contact', '/contact/unblock', true)); }
public function __call($method, $params = array()) { if (!isset(self::$helpers[$method])) { $class = '\\' . Config::getInstance()->get('b8.app.namespace') . '\\Helper\\' . $method; if (!class_exists($class)) { $class = '\\b8\\View\\Helper\\' . $method; } if (!class_exists($class)) { throw new HttpException('Helper class does not exist: ' . $class); } self::$helpers[$method] = new $class($params); self::$helpers[$method]->view = $this; } return self::$helpers[$method]; }
/** * Get the correct field class for the form * * @param $type * @return null|string */ public static function getFieldClass($type) { $config = b8\Config::getInstance(); $try = '\\' . $config->get('site.namespace') . '\\Form\\Element\\' . $type; if (class_exists($try)) { return $try; } $try = '\\Octo\\Form\\Element\\' . $type; if (class_exists($try)) { return $try; } $try = '\\b8\\Form\\Element\\' . $type; if (class_exists($try)) { return $try; } return null; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; // For verbose mode we want to output all informational and above // messages to the symphony output interface. if ($input->hasOption('verbose') && $input->getOption('verbose')) { $this->logger->pushHandler(new OutputLogHandler($this->output, Logger::INFO)); } $config = Config::getInstance()->get('phpci.worker', []); if (empty($config['host']) || empty($config['queue'])) { $error = 'The worker is not configured. You must set a host and queue in your config.yml file.'; throw new \Exception($error); } $worker = new BuildWorker($config['host'], $config['queue']); $worker->setLogger($this->logger); $worker->setMaxJobs(Config::getInstance()->get('phpci.worker.max_jobs', -1)); $worker->startWorker(); }
/** * Sets up the twig template loader. */ public static function init() { self::$loader = new Twig_Loader_Filesystem(); $config = Config::getInstance(); foreach (array_reverse($config->get('Octo.paths.templates', [])) as $path) { self::$loader->addPath($path); } foreach (array_reverse($config->get('Octo.paths.admin_templates', [])) as $path) { self::$loader->addPath($path, 'admin'); } if (OCTO_CACHE_ENABLED) { self::$cache = OCTO_CACHE_PATH; } else { self::$cache = false; } self::$twig = new Twig_Environment(self::$loader, ['charset' => 'UTF-8', 'cache' => self::$cache, 'auto_reload' => true, 'strict_variables' => false]); $functions = []; Event::trigger('TemplateInit', $functions); foreach ($functions as $name => $callable) { self::addFunction($name, $callable); } self::$initialised = true; }
public static function getSessionKey() { return Config::getInstance()->get('site.namespace', 'octo') . '_member_id'; }
/** * Handle the payload when Github sends a Pull Request webhook. * * @param Project $project * @param array $payload */ protected function githubPullRequest(Project $project, array $payload) { // We only want to know about open pull requests: if (!in_array($payload['action'], array('opened', 'synchronize', 'reopened'))) { return array('status' => 'ok'); } $headers = array(); $token = \b8\Config::getInstance()->get('phpci.github.token'); if (!empty($token)) { $headers[] = 'Authorization: token ' . $token; } $url = $payload['pull_request']['commits_url']; $http = new \b8\HttpClient(); $http->setHeaders($headers); $response = $http->get($url); // Check we got a success response: if (!$response['success']) { throw new Exception('Could not get commits, failed API request.'); } $results = array(); $status = 'failed'; foreach ($response['body'] as $commit) { // Skip all but the current HEAD commit ID: $id = $commit['sha']; if ($id != $payload['pull_request']['head']['sha']) { $results[$id] = array('status' => 'ignored', 'message' => 'not branch head'); continue; } try { $branch = str_replace('refs/heads/', '', $payload['pull_request']['base']['ref']); $committer = $commit['commit']['author']['email']; $message = $commit['commit']['message']; $remoteUrlKey = $payload['pull_request']['head']['repo']['private'] ? 'ssh_url' : 'clone_url'; $extra = array('build_type' => 'pull_request', 'pull_request_id' => $payload['pull_request']['id'], 'pull_request_number' => $payload['number'], 'remote_branch' => $payload['pull_request']['head']['ref'], 'remote_url' => $payload['pull_request']['head']['repo'][$remoteUrlKey]); $results[$id] = $this->createBuild($project, $id, $branch, $committer, $message, $extra); $status = 'ok'; } catch (Exception $ex) { $results[$id] = array('status' => 'failed', 'error' => $ex->getMessage()); } } return array('status' => $status, 'commits' => $results); }
public function isActive() { $config = Config::getInstance(); $parts = explode($config->get('site.full_admin_url') . '/', $_SERVER['REQUEST_URI']); if (count($parts) < 2) { return; } $search = '/' . $parts[1]; if ($this->link == $search) { return true; } if ($this->hasActiveChildren()) { return true; } $partialMatch = substr($search, 0, strlen($this->link)) == $this->link; if ($this->hidden && !$this->isRoot() && !$this->hasChildren() && $partialMatch) { return true; } return false; }
protected function reloadConfig() { $configFile = PHPCI_DIR . 'PHPCI/config.yml'; $config = Config::getInstance(); if (file_exists($configFile)) { $config->loadYaml($configFile); } }