本文整理汇总了PHP中b8\Store\Factory类的典型用法代码示例。如果您正苦于以下问题:PHP Factory类的具体用法?PHP Factory怎么用?PHP Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startWorker
/**
* Start the worker.
*/
public function startWorker()
{
$this->pheanstalk->watch($this->queue);
$this->pheanstalk->ignore('default');
$buildStore = Factory::getStore('Build');
while ($this->run) {
// Get a job from the queue:
$job = $this->pheanstalk->reserve();
$this->checkJobLimit();
// Get the job data and run the job:
$jobData = json_decode($job->getData(), true);
if (!$this->verifyJob($job, $jobData)) {
continue;
}
$this->logger->addInfo('Received build #' . $jobData['build_id'] . ' from Beanstalkd');
// If the job comes with config data, reset our config and database connections
// and then make sure we kill the worker afterwards:
if (!empty($jobData['config'])) {
$this->logger->addDebug('Using job-specific config.');
$currentConfig = Config::getInstance()->getArray();
$config = new Config($jobData['config']);
Database::reset($config);
}
try {
$build = BuildFactory::getBuildById($jobData['build_id']);
} catch (\Exception $ex) {
$this->logger->addWarning('Build #' . $jobData['build_id'] . ' does not exist in the database.');
$this->pheanstalk->delete($job);
}
try {
// Logging relevant to this build should be stored
// against the build itself.
$buildDbLog = new BuildDBLogHandler($build, Logger::INFO);
$this->logger->pushHandler($buildDbLog);
$builder = new Builder($build, $this->logger);
$builder->execute();
// After execution we no longer want to record the information
// back to this specific build so the handler should be removed.
$this->logger->popHandler($buildDbLog);
} catch (\PDOException $ex) {
// If we've caught a PDO Exception, it is probably not the fault of the build, but of a failed
// connection or similar. Release the job and kill the worker.
$this->run = false;
$this->pheanstalk->release($job);
} catch (\Exception $ex) {
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());
$buildStore->save($build);
$build->sendStatusPostback();
}
// Reset the config back to how it was prior to running this job:
if (!empty($currentConfig)) {
$config = new Config($currentConfig);
Database::reset($config);
}
// Delete the job when we're done:
$this->pheanstalk->delete($job);
}
}
示例2: init
/**
* Initialise the controller, set up stores and services.
*/
public function init()
{
$this->buildStore = Store\Factory::getStore('Build');
$this->projectStore = Store\Factory::getStore('Project');
$this->projectService = new ProjectService($this->projectStore);
$this->buildService = new BuildService($this->buildStore);
}
示例3: execute
/**
* Creates an admin user in the existing PHPCI database
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
require PHPCI_DIR . 'bootstrap.php';
// Try to create a user account:
$adminEmail = $this->ask('Admin email address: ', true, FILTER_VALIDATE_EMAIL);
if (empty($adminEmail)) {
return;
}
$adminPass = $this->ask('Admin password: ');
$adminName = $this->ask('Admin name: ');
try {
$user = new \PHPCI\Model\User();
$user->setEmail($adminEmail);
$user->setName($adminName);
$user->setIsAdmin(1);
$user->setHash(password_hash($adminPass, PASSWORD_DEFAULT));
$store = \b8\Store\Factory::getStore('User');
$store->save($user);
print 'User account created!' . PHP_EOL;
} catch (\Exception $ex) {
print 'There was a problem creating your account. :(' . PHP_EOL;
print $ex->getMessage();
print PHP_EOL;
}
}
示例4: change
public function change()
{
$count = 100;
$this->metaStore = \b8\Store\Factory::getStore('BuildMeta');
$this->errorStore = \b8\Store\Factory::getStore('BuildError');
while ($count == 100) {
$data = $this->metaStore->getErrorsForUpgrade(100);
$count = count($data);
/** @var \PHPCI\Model\BuildMeta $meta */
foreach ($data as $meta) {
try {
switch ($meta->getMetaKey()) {
case 'phpmd-data':
$this->processPhpMdMeta($meta);
break;
case 'phpcs-data':
$this->processPhpCsMeta($meta);
break;
case 'phpdoccheck-data':
$this->processPhpDocCheckMeta($meta);
break;
case 'phpcpd-data':
$this->processPhpCpdMeta($meta);
break;
case 'technicaldebt-data':
$this->processTechnicalDebtMeta($meta);
break;
}
} catch (\Exception $ex) {
}
$this->metaStore->delete($meta);
}
}
}
示例5: getBuildById
/**
* @param $buildId
* @return Build
* @throws \Exception
*/
public static function getBuildById($buildId)
{
$build = Factory::getStore('Build')->getById($buildId);
if (empty($build)) {
throw new \Exception('Build ID ' . $buildId . ' does not exist.');
}
return self::getBuild($build);
}
示例6: get
/**
* @param string $store Name of the store you want to load.
* @return \b8\Store
*/
public static function get($store)
{
$namespace = self::getModelNamespace($store);
if (!is_null($namespace)) {
return Factory::getStore($store, $namespace);
}
return null;
}
示例7: write
protected function write(array $record)
{
$message = (string) $record['message'];
$message = str_replace($this->build->currentBuildPath, '/', $message);
$this->logValue .= $message . PHP_EOL;
$this->build->setLog($this->logValue);
Factory::getStore('Build')->save($this->build);
}
示例8: execute
/**
* Loops through running.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$runner = new RunCommand($this->logger);
$runner->setMaxBuilds(1);
$runner->setDaemon(false);
/** @var \PHPCI\Store\BuildStore $store */
$store = Factory::getStore('Build');
$service = new BuildService($store);
$lastBuild = array_shift($store->getLatestBuilds(null, 1));
$service->createDuplicateBuild($lastBuild);
$runner->run(new ArgvInput(array()), $output);
}
示例9: getPreviousBuild
/**
* Return the previous build from a specific branch, for this project.
* @param string $branch
* @return mixed|null
*/
public function getPreviousBuild($branch = 'master')
{
$criteria = array('branch' => $branch, 'project_id' => $this->getId());
$order = array('id' => 'DESC');
$builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 1, array(), $order);
if (is_array($builds['items']) && count($builds['items'])) {
$previous = array_shift($builds['items']);
if (isset($previous) && $previous instanceof Build) {
return $previous;
}
}
return null;
}
示例10: index
/**
* List project groups.
*/
public function index()
{
$this->requireAdmin();
$groups = array();
$groupList = $this->groupStore->getWhere(array(), 100, 0, array(), array('title' => 'ASC'));
foreach ($groupList['items'] as $group) {
$thisGroup = array('title' => $group->getTitle(), 'id' => $group->getId());
$projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId());
$thisGroup['projects'] = $projects['items'];
$groups[] = $thisGroup;
}
$this->view->groups = $groups;
}
示例11: change
public function change()
{
$table = $this->table('project_group');
$table->addColumn('title', 'string', array('limit' => 100, 'null' => false));
$table->save();
$group = new \PHPCI\Model\ProjectGroup();
$group->setTitle('Projects');
/** @var \PHPCI\Model\ProjectGroup $group */
$group = \b8\Store\Factory::getStore('ProjectGroup')->save($group);
$table = $this->table('project');
$table->addColumn('group_id', 'integer', array('signed' => true, 'null' => false, 'default' => $group->getId()));
$table->addForeignKey('group_id', 'project_group', 'id', array('delete' => 'RESTRICT', 'update' => 'CASCADE'));
$table->save();
}
示例12: getLatestBuild
public function getLatestBuild($branch = 'master', $status = null)
{
$criteria = array('branch' => $branch, 'project_id' => $this->getId());
if (isset($status)) {
$criteria['status'] = $status;
}
$order = array('id' => 'DESC');
$builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 0, array(), $order);
if (is_array($builds['items']) && count($builds['items'])) {
$latest = array_shift($builds['items']);
if (isset($latest) && $latest instanceof Build) {
return $latest;
}
}
return null;
}
示例13: execute
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));
}
$store = Factory::getStore('Build');
$result = $store->getByStatus(0);
$this->logger->addInfo(Lang::get('found_n_builds', count($result['items'])));
$buildService = new BuildService($store);
while (count($result['items'])) {
$build = array_shift($result['items']);
$build = BuildFactory::getBuild($build);
$this->logger->addInfo('Added build #' . $build->getId() . ' to queue.');
$buildService->addBuildToQueue($build);
}
}
示例14: execute
/**
* Pulls all pending builds from the database and runs them.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$parser = new Parser();
$yaml = file_get_contents(APPLICATION_PATH . 'PHPCI/config.yml');
$this->settings = $parser->parse($yaml);
$token = $this->settings['phpci']['github']['token'];
if (!$token) {
$this->logger->error(Lang::get('no_token'));
return;
}
$buildStore = Factory::getStore('Build');
$this->logger->addInfo(Lang::get('finding_projects'));
$projectStore = Factory::getStore('Project');
$result = $projectStore->getWhere();
$this->logger->addInfo(Lang::get('found_n_projects', count($result['items'])));
foreach ($result['items'] as $project) {
$http = new HttpClient('https://api.github.com');
$commits = $http->get('/repos/' . $project->getReference() . '/commits', array('access_token' => $token));
$last_commit = $commits['body'][0]['sha'];
$last_committer = $commits['body'][0]['commit']['committer']['email'];
$message = $commits['body'][0]['commit']['message'];
$this->logger->info(Lang::get('last_commit_is', $project->getTitle(), $last_commit));
if ($project->getLastCommit() != $last_commit && $last_commit != "") {
$this->logger->info(Lang::get('adding_new_build'));
$build = new Build();
$build->setProjectId($project->getId());
$build->setCommitId($last_commit);
$build->setStatus(Build::STATUS_NEW);
$build->setBranch($project->getBranch());
$build->setCreated(new \DateTime());
$build->setCommitMessage($message);
if (!empty($last_committer)) {
$build->setCommitterEmail($last_committer);
}
$buildStore->save($build);
$project->setLastCommit($last_commit);
$projectStore->save($project);
}
}
$this->logger->addInfo(Lang::get('finished_processing_builds'));
}
示例15: execute
/**
* Creates an admin user in the existing PHPCI database
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$userStore = Factory::getStore('User');
$userService = new UserService($userStore);
require PHPCI_DIR . 'bootstrap.php';
// Try to create a user account:
$adminEmail = $this->ask('Admin email address: ', true, FILTER_VALIDATE_EMAIL);
if (empty($adminEmail)) {
return;
}
$adminPass = $this->ask('Admin password: ');
$adminName = $this->ask('Admin name: ');
try {
$userService->createUser($adminName, $adminEmail, $adminPass, 1);
print 'User account created!' . PHP_EOL;
} catch (\Exception $ex) {
print 'There was a problem creating your account. :(' . PHP_EOL;
print $ex->getMessage();
print PHP_EOL;
}
}