/**
  * Function creates validator object using IoC calls
  *
  * @return AbstractValidator
  * @throws Exception
  */
 protected static function createValidator()
 {
     $className = self::getValidatorClass();
     if (!class_exists($className)) {
         throw new Exception("Cannot load validator class '{$className}' for model '" . static::class . "'");
     }
     return Application::getInstance()->make($className);
 }
 /**
  * Registers provided closure as a validation rule. Useful for quick & dirty validation
  *
  * @param string              $ruleName
  * @param string|Closure      $validateFunction
  * @param string|Closure|null $replaceFunction
  */
 public static function registerClosure($ruleName, $validateFunction, $replaceFunction = null)
 {
     /** @var Factory $validatorFactory */
     $validatorFactory = Application::getInstance()->make(Factory::class);
     $validatorFactory->extend($ruleName, $validateFunction);
     if (null !== $replaceFunction) {
         $validatorFactory->replacer($ruleName, $replaceFunction);
     }
 }
Example #3
0
 function __construct()
 {
     $filePath = Application::getInstance()->storagePath() . '/files/pinyin.db';
     if (file_exists($filePath)) {
         $records = file($filePath);
         foreach ($records as $record) {
             $record = trim($record);
             $this->map[substr($record, 0, 3)] = substr($record, 4, strlen($record) - 3);
         }
     }
 }
Example #4
0
 /**
  * Set the globally available instance of the container.
  *
  * @return static 
  * @static 
  */
 public static function getInstance()
 {
     //Method inherited from \Illuminate\Container\Container
     return \Illuminate\Foundation\Application::getInstance();
 }
Example #5
0
 public function __construct($items = [], $addons = null)
 {
     parent::__construct($items);
     $this->app = \Illuminate\Foundation\Application::getInstance();
     $this->addons = $addons ?: $this->app->make('codex.addons');
 }
 /**
  * @return string
  * @author Rytis Grincevičius <*****@*****.**>
  */
 public static function getLocale()
 {
     return Application::getInstance()->getLocale();
 }
Example #7
0
 /**
  * @param string $path
  * @param string $locale
  * @return string
  * @author Rytis Grincevičius <*****@*****.**>
  */
 public static function translation_path($path = '', $locale = '')
 {
     $locale = $locale ? $locale : Application::getInstance()->getLocale();
     $path = self::parse_path($path);
     return self::translations_path($locale . ($path ? DIRECTORY_SEPARATOR . $path : $path));
 }