本文整理汇总了PHP中Yii::createObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::createObject方法的具体用法?PHP Yii::createObject怎么用?PHP Yii::createObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::createObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: optionsModifier
protected function optionsModifier($options)
{
if (empty($this->component)) {
throw new InvalidConfigException('The "component" property must be set.');
}
/** @var Filesystem $component */
if (is_string($this->component)) {
$component = \Yii::$app->get($this->component);
} else {
$component = \Yii::createObject($this->component);
}
if (!($component instanceof \creocoder\flysystem\Filesystem || $component instanceof Filesystem)) {
throw new InvalidConfigException('A Filesystem instance is required');
}
$options['separator'] = $this->separator;
$options['filesystem'] = new Filesystem($component->getAdapter());
$options['path'] = $this->path;
if (!empty($this->glideURL) && !empty($this->glideKey)) {
$options['glideURL'] = $this->glideURL;
$options['glideKey'] = $this->glideKey;
unset($options['tmbPath']);
unset($options['tmbURL']);
}
if (!empty($this->url)) {
$options['URL'] = $this->url;
}
return $options;
}
示例2: init
/**
* Try to read language from session and cookies
*/
public function init()
{
parent::init();
$slug = null;
if ($this->languageSession) {
$slug = Yii::$app->session->get($this->languageSessionKey);
}
if ($slug === null && $this->languageCookie) {
$slug = Yii::$app->request->getCookies()->getValue($this->languageCookieName);
}
$languages = [];
$selectedLanguage = null;
foreach ($this->languages as $config) {
if (is_array($config) && !isset($config['class'])) {
$config['class'] = Language::className();
}
/** @var ILanguage $language */
$language = \Yii::createObject($config);
$languages[$language->getId()] = $language;
if ($slug === $language->getSlug()) {
$selectedLanguage = $language;
}
}
$this->languages = $languages;
if ($selectedLanguage === null) {
$selectedLanguage = reset($languages);
}
$this->setLanguage($selectedLanguage);
}
示例3: deferEvent
public function deferEvent($event)
{
$class = get_class($this->owner);
$pk = $this->owner->getPrimaryKey();
$attributes = $this->owner->getAttributes();
$scenario = $this->owner->scenario;
$eventName = $event->name;
$queue = $this->queue;
$handler = clone $this;
$handler->queue = null;
$handler->owner = null;
/* @var $queue Queue */
if ($eventName == ActiveRecord::EVENT_AFTER_DELETE) {
$queue->post(new \UrbanIndo\Yii2\Queue\Job(['route' => function () use($class, $pk, $attributes, $handler, $eventName, $scenario) {
$object = \Yii::createObject($class);
/* @var $object ActiveRecord */
$object->setAttributes($attributes, false);
$object->scenario = $scenario;
$handler->handleEvent($object);
}]));
} else {
$queue->post(new \UrbanIndo\Yii2\Queue\Job(['route' => function () use($class, $pk, $attributes, $handler, $eventName, $scenario) {
$object = $class::findOne($pk);
if ($object === null) {
throw new \Exception("Model is not found");
}
$object->scenario = $scenario;
/* @var $object ActiveRecord */
$handler->handleEvent($object);
}]));
}
}
示例4: register
public function register()
{
if ($this->getIsNewRecord() == false) {
throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
}
if ($this->module->enableConfirmation == false) {
$this->confirmed_at = time();
}
if ($this->module->enableGeneratingPassword) {
$this->password = Password::generate(8);
}
$this->trigger(self::USER_REGISTER_INIT);
if ($this->save()) {
$this->trigger(self::USER_REGISTER_DONE);
if ($this->module->enableConfirmation) {
$token = \Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]);
$token->link('user', $this);
$this->mailer->sendConfirmationMessage($this, $token);
} else {
\Yii::$app->user->login($this);
}
if ($this->module->enableGeneratingPassword) {
$this->mailer->sendWelcomeMessage($this);
}
\Yii::$app->session->setFlash('info', $this->getFlashMessage());
\Yii::getLogger()->log('User has been registered', Logger::LEVEL_INFO);
return true;
}
\Yii::getLogger()->log('An error occurred while registering user account', Logger::LEVEL_ERROR);
return false;
}
示例5: publish
public function publish($channel, $message)
{
if ($this->redis === null) {
$this->redis = \Yii::createObject(['class' => \kepco\Redis::className(), 'hostname' => $this->redis_server]);
}
$this->redis->publish($channel, $message);
}
示例6: beforeAction
public function beforeAction($action)
{
$device = new MobileDetect();
$theme = ['class' => 'yii\\base\\Theme', 'basePath' => '@app/themes/basic', 'baseUrl' => '@web/themes/basic', 'pathMap' => ['@app/views' => ['@app/themes/' . ($device->isMobile() ? 'mobile' : 'special'), '@app/themes/basic']]];
\Yii::$app->getView()->theme = \Yii::createObject($theme);
return true;
}
示例7: transfer
/**
* @return \metalguardian\fileProcessor\components\FileTransfer
* @throws \yii\base\InvalidConfigException
*/
public static function transfer()
{
if (is_null(static::$transfer)) {
static::$transfer = \Yii::createObject(\metalguardian\fileProcessor\components\FileTransfer::className());
}
return static::$transfer;
}
示例8: save
/**
* @param \yii\authclient\ClientInterface $Client
* @return bool
* @throws \yii\base\InvalidConfigException
*/
public function save(\yii\authclient\ClientInterface $Client)
{
/** @var Account\backend\Module $Module */
$Module = \Yii::$app->getModule($this->accountModule);
$roles = $Module->roles;
/** @var AccountModel $Account */
$Account = \Yii::createObject(AccountModel::class);
$Account->appendClientAttributes($Client);
$Account->setAttributes(['email' => $this->email]);
$Account->validate() && $Account->save();
$AuthResponse = AccountAuthResponseModel::createLog($Client);
if ($Account->hasErrors()) {
$AuthResponse->result = Json::encode($Account->getErrors());
} else {
$AuthResponse->result = (string) $Account->id;
$Account->pushSocialLink($Client);
AuthManager()->assign(RbacFactory::Role($roles['user']), $Account->id);
$SignInFormModel = \Yii::createObject(SignInForm::class);
User()->login($Account, $SignInFormModel::REMEMBER_TIME);
}
$AuthResponse->validate() && $AuthResponse->save();
if ($Account->hasErrors()) {
$this->populateErrors($Account, 'name');
}
return !$Account->hasErrors();
}
示例9: editable
/**
* @return EditableFactory
* @throws \yii\base\InvalidConfigException
*/
public function editable()
{
if ($this->editable === null) {
$this->editable = Yii::createObject(EditableFactory::class, $this->editableConfig);
}
return $this->editable;
}
示例10: init
public function init()
{
parent::init();
$this->layout = $this->layoutMittente;
//se sono il widget di destinazione per le scelte delle associazioni
if (!$this->targetUrl) {
$this->layout = $this->layoutTarget;
if (!$this->modelTargetSearch) {
throw new InvalidConfigException($this->throwErrorMessage('modelTargetSearch'));
}
if (!$this->modelTargetSearch['class']) {
throw new InvalidConfigException($this->throwErrorMessage('modelTargetSearch[class]'));
}
if (!$this->modelTargetSearch['action']) {
throw new InvalidConfigException($this->throwErrorMessage('modelTargetSearch[action]'));
}
$this->modelTarget = \Yii::createObject($this->modelTargetSearch['class']);
$this->modelTargetData = $this->modelTarget->{$this->modelTargetSearch['action']}(\Yii::$app->request->getQueryParams());
}
if (!$this->modelData) {
throw new InvalidConfigException($this->throwErrorMessage('modelData'));
}
if (!$this->modelId) {
throw new InvalidConfigException($this->throwErrorMessage('modelId'));
}
if (!$this->model) {
throw new InvalidConfigException($this->throwErrorMessage('model'));
}
$this->modelDataArr = ArrayHelper::map($this->modelData->all(), 'id', 'id');
}
示例11: init
/**
* Initialization
*
* @param array $config
* @return \phantomd\filedaemon\FileProcessing Object
* @throws InvalidParamException
*/
public static function init($config)
{
if (empty($config)) {
$message = 'Component error: Could not be empty `config`!';
\Yii::error($message, __METHOD__ . '(' . __LINE__ . ')');
throw new InvalidParamException($message);
}
$class = null;
if (false === empty($config['component'])) {
if (class_exists($config['component'])) {
$class = $config['component'];
} else {
$class = __NAMESPACE__ . '\\' . ucfirst(strtolower((string) $config['component'])) . 'Processing';
}
}
if ($class) {
if (false === class_exists($class)) {
$message = "Component error: Not exist - `{$class}`";
\Yii::error($message, __METHOD__ . '(' . __LINE__ . ')');
throw new InvalidParamException($message);
}
$params = ['class' => $class, 'config' => $config];
$object = \Yii::createObject($params);
if ($object instanceof FileProcessing) {
return $object;
} else {
$message = "Component error: `{$class}` must be instance of class `FileProcessing`!";
\Yii::error($message, __METHOD__ . '(' . __LINE__ . ')');
throw new InvalidParamException($message);
}
}
return null;
}
示例12: run
public function run()
{
if ($this->checkAccess) {
call_user_func($this->checkAccess, $this->id);
}
$params = Yii::$app->request->post();
if (!isset($params['language'])) {
throw new HttpException(404, Yii::t('cza', 'Language ({s1}) Not Found!', ['s1' => $params['language']]));
}
if (isset($params['src_model_id'])) {
$model = $this->controller->retrieveModel($params['src_model_id']);
} else {
throw new HttpException(404, Yii::t('cza', 'Srouce model not found!'));
}
$translationModel = $model->getTranslation($params['language']);
// handle cms media fields
if ($this->controller instanceof \cza\base\components\controllers\backend\CmsController) {
$cmsFields = $this->controller->getCmsFields();
$translationModel->attachBehavior('CmsMediaBehavior', ['class' => CmsMediaBehavior::className(), 'fields' => $cmsFields, 'options' => ['isTranslation' => true]]);
}
if ($translationModel->load($params) && $translationModel->save()) {
$responseData = \cza\base\models\statics\ResponseDatum::getSuccessDatum($_POST, array('message' => Yii::t('cza', 'Operation completed successfully!')));
} else {
$responseData = \cza\base\models\statics\ResponseDatum::getErrorDatum($_POST, array('message' => $translationModel->getFirstErrors()));
}
return \Yii::createObject(['class' => 'yii\\web\\Response', 'format' => \yii\web\Response::FORMAT_JSON, 'data' => $responseData]);
}
示例13: testJsonSerialize
/**
* Tests the `LogTarget::jsonSerialize` method.
*/
public function testJsonSerialize()
{
$client = \Yii::createObject(['class' => Client::class, 'password' => 'secret', 'username' => 'anonymous']);
$data = (new LogTarget(['client' => $client]))->jsonSerialize();
$this->assertObjectHasAttribute('enabled', $data);
$this->assertTrue($data->enabled);
}
示例14: get
public static function get($id)
{
$query = is_numeric($id) ? ['clientid' => $id] : ['email' => $id];
$response = self::getWhmcs()->call('getclientsdetails', $query, false);
\Yii::trace(VarDumper::dumpAsString($response), __METHOD__);
return \Yii::createObject(self::className(), [$response]);
}
示例15: testLogin
public function testLogin()
{
$this->form = \Yii::createObject(LoginForm::className());
$this->specify('should not allow logging in blocked users', function () {
$user = $this->getFixture('user')->getModel('blocked');
$this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
verify($this->form->validate())->false();
verify($this->form->getErrors('login'))->contains('Your account has been blocked');
});
$this->specify('should not allow logging in unconfirmed users', function () {
\Yii::$app->getModule('user')->enableConfirmation = true;
\Yii::$app->getModule('user')->enableUnconfirmedLogin = false;
$user = $this->getFixture('user')->getModel('user');
$this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
verify($this->form->validate())->true();
$user = $this->getFixture('user')->getModel('unconfirmed');
$this->form->setAttributes(['login' => $user->email, 'password' => 'unconfirmed']);
verify($this->form->validate())->false();
});
$this->specify('should log the user in with correct credentials', function () {
$user = $this->getFixture('user')->getModel('user');
$this->form->setAttributes(['login' => $user->email, 'password' => 'wrong']);
verify($this->form->validate())->false();
$this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
verify($this->form->validate())->true();
});
}