本文整理汇总了PHP中Phalcon\DI\FactoryDefault::getDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP FactoryDefault::getDefault方法的具体用法?PHP FactoryDefault::getDefault怎么用?PHP FactoryDefault::getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DI\FactoryDefault
的用法示例。
在下文中一共展示了FactoryDefault::getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEnumValues
/**
* Get Enum Column values
*
* @access public
* @param {string} $columnName
* @return {array}
*/
public function getEnumValues($columnName = null)
{
$di = PhDi::getDefault();
if ($columnName == null) {
return array();
}
$sql = "SHOW COLUMNS FROM `" . $this->getSource() . "` LIKE '{$columnName}'";
$resultSet = $di['db']->query($sql);
$resultSet->setFetchMode(Phalcon\Db::FETCH_ASSOC);
$result = $resultSet->fetchAll($resultSet);
if (!empty($result)) {
$types = null;
if (isset($result[0]['Type'])) {
$types = $result[0]['Type'];
} else {
return array();
}
$values = explode("','", preg_replace("/(enum)\\('(.+?)'\\)/", "\\2", $types));
$assoc_values = array();
foreach ($values as $value) {
$assoc_values[$value] = ucwords(str_replace('_', ' ', $value));
}
return $assoc_values;
}
return false;
}
示例2: log
/**
* @param $name
* @param $message
* @param $type
*/
public static function log($name, $message, $type)
{
$typeName = self::getTypeString($type);
$logger = FactoryDefault::getDefault()->get('logger');
$logger->name = $name;
$logger->{$typeName}($message);
}
示例3: smarty_function_apretaste_support_email
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsFunction
*/
function smarty_function_apretaste_support_email($params, $template)
{
// get the support email from the configs
$di = \Phalcon\DI\FactoryDefault::getDefault();
$supportEmail = $di->get("config")["contact"]["support"];
return $supportEmail;
}
示例4: renderHTML
/**
* Render the template and return the HTML content
*
* @author salvipascual
* @param Service $service, service to be rendered
* @param Response $response, response object to render
* @return String, template in HTML
* @throw Exception
*/
public function renderHTML($service, $response)
{
// get the path
$di = \Phalcon\DI\FactoryDefault::getDefault();
$wwwroot = $di->get('path')['root'];
// select the right file to load
if ($response->internal) {
$userTemplateFile = "{$wwwroot}/app/templates/{$response->template}";
} else {
$userTemplateFile = "{$wwwroot}/services/{$service->serviceName}/templates/{$response->template}";
}
// creating and configuring a new Smarty object
$smarty = new Smarty();
$smarty->addPluginsDir("{$wwwroot}/app/plugins/");
$smarty->setTemplateDir("{$wwwroot}/app/layouts/");
$smarty->setCompileDir("{$wwwroot}/temp/templates_c/");
$smarty->setCacheDir("{$wwwroot}/temp/cache/");
// disabling cache and debugging
$smarty->force_compile = true;
$smarty->debugging = false;
$smarty->caching = false;
// list the system variables
$systemVariables = array("APRETASTE_USER_TEMPLATE" => $userTemplateFile, "APRETASTE_SERVICE_NAME" => strtoupper($service->serviceName), "APRETASTE_SERVICE_RELATED" => $this->getServicesRelatedArray($service->serviceName), "APRETASTE_SERVICE_CREATOR" => $service->creatorEmail, "APRETASTE_TOP_AD" => "", "APRETASTE_BOTTOM_AD" => "");
// merge all variable sets and assign them to Smarty
$templateVariables = array_merge($systemVariables, $response->content);
$smarty->assign($templateVariables);
// renderig and removing tabs, double spaces and break lines
$renderedTemplate = $smarty->fetch("email_default.tpl");
return preg_replace('/\\s+/S', " ", $renderedTemplate);
}
示例5: sendEmail
/**
* Sends an email using MailGun
* @author salvipascual
* @param String $to, email address of the receiver
* @param String $subject, subject of the email
* @param String $body, body of the email in HTML
* @param Array $images, paths to the images to embeb
* @param Array $attachments, paths to the files to attach
* */
public function sendEmail($to, $subject, $body, $images = array(), $attachments = array())
{
// do not email if there is an error
$response = $this->deliveryStatus($to);
if ($response != 'ok') {
return;
}
// select the from email using the jumper
$from = $this->nextEmail($to);
$domain = explode("@", $from)[1];
// create the list of images
if (!empty($images)) {
$images = array('inline' => $images);
}
// crate the list of attachments
// TODO add list of attachments
// create the array send
$message = array("from" => "Apretaste <{$from}>", "to" => $to, "subject" => $subject, "html" => $body, "o:tracking" => false, "o:tracking-clicks" => false, "o:tracking-opens" => false);
// get the key from the config
$di = \Phalcon\DI\FactoryDefault::getDefault();
$mailgunKey = $di->get('config')['mailgun']['key'];
// send the email via MailGun
$mgClient = new Mailgun($mailgunKey);
$result = $mgClient->sendMessage($domain, $message, $images);
}
示例6: logError
/**
* Write error to log
*
* @param $type
* @param $message
* @param $file
* @param $line
* @param string $trace
* @throws \Phalcon\Exception
*/
protected static function logError($type, $message, $file, $line, $trace = '')
{
$di = Di::getDefault();
$template = "[%s] %s (File: %s Line: [%s])";
$logMessage = sprintf($template, $type, $message, $file, $line);
if ($di->has('profiler')) {
$profiler = $di->get('profiler');
if ($profiler) {
$profiler->addError($logMessage, $trace);
}
}
if ($trace) {
$logMessage .= $trace . PHP_EOL;
} else {
$logMessage .= PHP_EOL;
}
if ($di->has('logger')) {
$logger = $di->get('logger');
if ($logger) {
$logger->error($logMessage);
} else {
throw new PhException($logMessage);
}
} else {
throw new PhException($logMessage);
}
}
示例7: escape
/**
* Escape dangerous strings before passing it to mysql
*
* @author salvipascual
* @param String $str, text to scape
* @return String, scaped text ready to be sent to mysql
* */
public function escape($str)
{
// get the scaped string
$di = \Phalcon\DI\FactoryDefault::getDefault();
$safeStr = $di->get('db')->escapeString($str);
// remove the ' at the beginning and end of the string
return substr(substr($safeStr, 0, -1), 1);
}
示例8: __construct
/**
* Creates the profiler and starts the logging
*/
public function __construct()
{
$this->_profiler = new Profiler();
$di = Di::getDefault();
if ($di->has('loggerDb')) {
$this->_logger = $di->get('loggerDb');
}
}
示例9: countMediumtypeClippings
public function countMediumtypeClippings($mediumtype)
{
$config = \Phalcon\DI\FactoryDefault::getDefault()->getShared('config');
$modelsManager = $this->getDi()->getShared('modelsManager');
$phql = 'SELECT COUNT(clippings.uid) as clippingscount, SUM(medium.reach) as mediumreach FROM reportingtool\\Models\\Clippings as clippings LEFT JOIN reportingtool\\Models\\Projects as projects ON projects.uid=clippings.pid LEFT JOIN reportingtool\\Models\\Medium as medium ON medium.uid=clippings.mediumuid ' . 'WHERE medium.deleted =0 AND medium.hidden=0 AND clippings.deleted=0 AND clippings.hidden =0 AND projects.deleted=0 AND projects.hidden = 0 AND medium.mediumtype = ?1';
$sQuery = $modelsManager->createQuery($phql);
$rResults = $sQuery->execute(array(1 => $mediumtype));
return $rResults[0];
}
示例10: __construct
public function __construct()
{
$this->config = DI::getDefault()->get('config');
$this->searcher = new SphinxClient();
$this->searcher->SetServer($this->config->app_sphinx->host, $this->config->app_sphinx->port);
$this->searcher->SetConnectTimeout(1);
$this->searcher->SetArrayResult(true);
$this->searcher->SetMatchMode(SPH_MATCH_EXTENDED2);
$this->searcher->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
}
示例11: render
public function render($attributes = NULL)
{
// Konfiguration beziehen
$config = FactoryDefault::getDefault()->getConfig();
// HTML-Code erzeugen
$html = '<div class="g-recaptcha" data-sitekey="%1$s"></div>';
$html .= '<script src="//www.google.com/recaptcha/api.js?hl=%2$s"></script>';
// Platzhalter füllen und HTML zurückgeben
return sprintf($html, $config->ReCaptcha->siteKey, $config->ReCaptcha->language);
}
示例12: getDi
/**
* Gets the dependency injector
* @return DiInterface
*/
public function getDi()
{
if (is_null($this->di)) {
$this->di = FactoryDefault::getDefault();
if (is_null($this->di)) {
$this->di = new FactoryDefault();
}
}
return $this->di;
}
示例13: beforeSave
public function beforeSave()
{
$path = dirname(__FILE__);
$di = Di::getDefault();
foreach ($this->behaviors as $behavior => $active) {
if ($active && $di->has($behavior)) {
$di->get($behavior)->beforeSave($this);
}
}
}
示例14: user
/**
* Get the user that owns the subscription.
*/
public function user()
{
$di = FactoryDefault::getDefault();
$stripe = $di->getConfig()->stripe;
$model = $stripe->model ?: getenv('STRIPE_MODEL');
if (!isset($model)) {
throw new Exception('You need add config model for stripe!');
}
$this->belongsTo('user_id', $model, 'id', ['alias' => 'user']);
return $this->getRelated('user');
}
示例15: toFormat
public function toFormat($data)
{
$callback = isset($_GET['callback']) && !empty($_GET['callback']) ? $_GET['callback'] . '(' : '';
$suffix = !empty($callback) ? ');' : '';
$data = $callback . json_encode($data) . $suffix;
$error = json_last_error();
if (empty($data) && $error != JSON_ERROR_NONE) {
$di = \Phalcon\DI\FactoryDefault::getDefault();
$di['response']->internalServerError('Unable to write format.');
}
return $data;
}