Example #1
0
 /**
  * Get the given plugin as an object, or a collection of objects if not
  * specified.
  *
  * @param string $plugin Plugin name to get, or null to get a collection of
  *  all plugin objects
  * @return \CMS\Core\Package\PluginPackage|\Cake\Collection\Collection
  * @throws \Cake\Error\FatalErrorException When requested plugin was not found
  */
 public static function get($plugin = null)
 {
     $cacheKey = "get({$plugin})";
     $cache = static::cache($cacheKey);
     if ($cache !== null) {
         return $cache;
     }
     if ($plugin === null) {
         $collection = [];
         foreach ((array) quickapps('plugins') as $plugin) {
             $plugin = PackageFactory::create($plugin['name']);
             if ($plugin instanceof PluginPackage) {
                 $collection[] = $plugin;
             }
         }
         return static::cache($cacheKey, collection($collection));
     }
     $package = PackageFactory::create($plugin);
     if ($package instanceof PluginPackage) {
         return static::cache($cacheKey, $package);
     }
     throw new FatalErrorException(__d('cms', 'Plugin "{0}" was not found', $plugin));
 }
Example #2
0
 /**
  * Checks all the rules of this class.
  *
  * @return bool True if all rules are meet
  */
 public function check()
 {
     $pass = true;
     foreach ($this->_rules as $rule) {
         if ($rule->lhs() instanceof BasePackage) {
             $package = $rule->lhs();
         } else {
             $package = PackageFactory::create((string) $rule->lhs());
         }
         if (!$package->versionMatch($rule->rhs())) {
             $this->_fail($rule);
             $pass = false;
         } else {
             $this->_pass($rule);
         }
     }
     $this->_checked = true;
     return $pass;
 }