checkRequirements() public static method

This method will check the existence of ImageMagick and GD extensions.
public static checkRequirements ( ) : string
return string the name of the graphic extension, either "imagick" or "gd".
Example #1
0
 /**
  * Renders the CAPTCHA image.
  * @param string $code the verification code
  * @return string image contents
  */
 protected function renderImage($code)
 {
     if (Captcha::checkRequirements() === 'gd') {
         return $this->renderImageByGD($code);
     } else {
         return $this->renderImageByImagick($code);
     }
 }
Example #2
0
 /**
  * Renders the CAPTCHA image.
  * @param string $code the verification code
  * @return string image contents
  * @throws InvalidConfigException if imageLibrary is not supported
  */
 protected function renderImage($code)
 {
     if (isset($this->imageLibrary)) {
         $imageLibrary = $this->imageLibrary;
     } else {
         $imageLibrary = Captcha::checkRequirements();
     }
     if ($imageLibrary === 'gd') {
         return $this->renderImageByGD($code);
     } elseif ($imageLibrary === 'imagick') {
         return $this->renderImageByImagick($code);
     } else {
         throw new InvalidConfigException("Defined library '{$imageLibrary}' is not supported");
     }
 }
Example #3
0
 /**
  * A factory to create pre-configured form models. Only model class names
  * from the nineinchnick\usr\models namespace are allowed.
  * Sets scenario, password strength rules for models extending BasePasswordForm and attaches behaviors.
  *
  * @param  string $class    without the namespace
  * @param  string $scenario
  * @return Model
  */
 public function createFormModel($class, $scenario = null)
 {
     $namespacedClass = "\\nineinchnick\\usr\\models\\{$class}";
     /** @var Model */
     $form = new $namespacedClass();
     if ($scenario !== null) {
         $form->setScenario($scenario);
     }
     if ($form instanceof \nineinchnick\usr\models\BaseUsrForm) {
         $form->webUser = Yii::$app->user;
     }
     if ($form instanceof \nineinchnick\usr\models\BasePasswordForm) {
         $form->passwordStrengthRules = $this->passwordStrengthRules;
     }
     switch ($class) {
         default:
             break;
         case 'ProfileForm':
             $form->pictureUploadRules = $this->pictureUploadRules;
             if (!empty($this->profileFormBehaviors)) {
                 foreach ($this->profileFormBehaviors as $name => $config) {
                     $form->attachBehavior($name, $config);
                 }
             }
             // no break
         // no break
         case 'RecoveryForm':
             if ($this->captcha !== null && \yii\captcha\Captcha::checkRequirements()) {
                 $form->attachBehavior('captcha', ['class' => 'nineinchnick\\usr\\components\\CaptchaFormBehavior', 'ruleOptions' => $class == 'ProfileForm' ? ['on' => 'register'] : ['except' => ['reset', 'verify']]]);
             }
             break;
         case 'LoginForm':
             if ($this->loginFormBehaviors !== null && is_array($this->loginFormBehaviors)) {
                 foreach ($this->loginFormBehaviors as $name => $config) {
                     $form->attachBehavior($name, $config);
                 }
             }
             break;
         case 'AuthForm':
             $form->setValidProviders(array_keys(Yii::$app->get('authClientCollection')->clients));
             break;
     }
     return $form;
 }
 public function rules()
 {
     return array([['username'], 'required', 'message' => '请输入用户名'], [['username'], 'required', 'message' => '请输入密码'], [['username'], 'checkUserNameAndPassword'], [['password'], 'checkUserNameAndPassword'], [['verifyCode'], 'captcha', 'skipOnEmpty' => !Captcha::checkRequirements(), 'message' => '验证码不正确']);
 }