Takes an array of classes and returns the
classes which are available with the
current permissions/policy set.

@param array $classes

@return array
11120
public function getSubAdminClasses(array $classes)
    {
        $classCollection = [];

        foreach ($classes as $key => $class) {
            if ($this->usableClass($key)) {
                $classCollection[] = [$key => $this->getSubAdminClasses($class)];
                continue;
            }

            if ($this->usableClass($class)) {
                $classCollection[] = $class;
                continue;
            }
        }

        return $classCollection;
    }
1038970
public static function getByClass( $class )
	{
		$results = [];
		foreach ( static::$globals as $k => $v )
			if ( $v instanceof $class )
				$results[$k] = $v;
		return $results;
	}
132805
private function getBundlePathsUsingNamedObj(array $classes)
    {
        $paths = [];

        foreach ($classes as $c) {
            try {
                $r = new \ReflectionClass($c);
            } catch (\ReflectionException $exception) {
                throw new InvalidArgumentException(sprintf('Unable to resolve bundle "%s" while auto-registering bundle resource paths.', $c), null, $exception);
            }

            $paths[$r->getShortName()] = \dirname($r->getFileName());
        }

        return $paths;
    }
451626
public function filterClassNames(array $statements)
    {
        $names = [];
        foreach ($this->filterClasses($statements) as $class) {
            $names[] = $class->name;
        }

        foreach ($this->filterNamespaces($statements) as $namespace) {
            foreach ($this->filterClasses($namespace->stmts) as $class) {
                $names[] = $namespace->name.'\\'.$class->name;
            }
        }

        return $names;
    }
1129172
public function getClassesApi()
    {
        if (!$this->apis->has('classes')) {
            $this->apis->set('classes', new Classes($this));
        }

        return $this->apis->get('classes');
    }
675820
protected function guessPolicyName($class)
    {
        if ($this->guessPolicyNamesUsingCallback) {
            return Arr::wrap(call_user_func($this->guessPolicyNamesUsingCallback, $class));
        }

        $classDirname = str_replace('/', '\\', dirname(str_replace('\\', '/', $class)));

        return [$classDirname.'\\Policies\\'.class_basename($class).'Policy'];
    }
1010319
public function sidebarClass($classes = [])
    {
        $classes = !is_array($classes) ? explode(' ', $classes) : $classes;
        $classes[] = sprintf('sidebar-%s', $this->template);
        $classes[] = 'sidebar';
        $classes[] = 'col-sm-4 col-md-3';

        $classes = apply_filters('novusopress_view_sidebar_classes', $classes);
        $output = sprintf('class="%s"', implode(' ', $classes));

        return apply_filters('novusopress_view_sidebar_class_output', $output);
    }
1092878
protected function convertToPermissionModels($permissions): array
    {
        if ($permissions instanceof Collection) {
            $permissions = $permissions->all();
        }

        $permissions = is_array($permissions) ? $permissions : [$permissions];

        return array_map(function ($permission) {
            if ($permission instanceof Permission) {
                return $permission;
            }

            return $this->getPermissionClass()->findByName($permission, $this->getDefaultGuardName());
        }, $permissions);
    }
1316652
public static function guessClassFromTypes(array $types)
    {
        if (count($types)) {
            foreach (Resource::CLASSES as $class) {
                $class = "JSKOS\\$class";
                foreach ($class::TYPES as $uri) {
                    if (in_array($uri, $types)) {
                        return $class;
                    }
                }
            }
        }
    }
450121
public function getSchemaFromMetadata(array $classes)
    {
        // Reminder for processed classes, used for hierarchies
        $processedClasses     = [];
        $eventManager         = $this->em->getEventManager();
        $schemaManager        = $this->em->getConnection()->getSchemaManager();
        $metadataSchemaConfig = $schemaManager->createSchemaConfig();

        $metadataSchemaConfig->setExplicitForeignKeyIndexes(false);
        $schema = new Schema([], [], $metadataSchemaConfig);

        $addedFks       = [];
        $blacklistedFks = [];

        foreach ($classes as $class) {
            /** @var ClassMetadata $class */
            if ($this->processingNotRequired($class, $processedClasses)) {
                continue;
            }

            $table = $schema->createTable($class->table->getQuotedQualifiedName($this->platform));

            switch ($class->inheritanceType) {
                case InheritanceType::SINGLE_TABLE:
                    $this->gatherColumns($class, $table);
                    $this->gatherRelationsSql($class, $table, $schema, $addedFks, $blacklistedFks);

                    // Add the discriminator column
                    $this->addDiscriminatorColumnDefinition($class, $table);

                    // Aggregate all the information from all classes in the hierarchy
                    $parentClass = $class;

                    while (($parentClass = $parentClass->getParent()) !== null) {
                        // Parent class information is already contained in this class
                        $processedClasses[$parentClass->getClassName()] = true;
                    }

                    foreach ($class->getSubClasses() as $subClassName) {
                        $subClass = $this->em->getClassMetadata($subClassName);

                        $this->gatherColumns($subClass, $table);
                        $this->gatherRelationsSql($subClass, $table, $schema, $addedFks, $blacklistedFks);

                        $processedClasses[$subClassName] = true;
                    }

                    break;

                case InheritanceType::JOINED:
                    // Add all non-inherited fields as columns
                    $pkColumns = [];

                    foreach ($class->getDeclaredPropertiesIterator() as $fieldName => $property) {
                        if (! ($property instanceof FieldMetadata)) {
                            continue;
                        }

                        if (! $class->isInheritedProperty($fieldName)) {
                            $columnName = $this->platform->quoteIdentifier($property->getColumnName());

                            $this->gatherColumn($class, $property, $table);

                            if ($class->isIdentifier($fieldName)) {
                                $pkColumns[] = $columnName;
                            }
                        }
                    }

                    $this->gatherRelationsSql($class, $table, $schema, $addedFks, $blacklistedFks);

                    // Add the discriminator column only to the root table
                    if ($class->isRootEntity()) {
                        $this->addDiscriminatorColumnDefinition($class, $table);
                    } else {
                        // Add an ID FK column to child tables
                        $inheritedKeyColumns = [];

                        foreach ($class->identifier as $identifierField) {
                            $idProperty = $class->getProperty($identifierField);

                            if ($class->isInheritedProperty($identifierField)) {
                                $column     = $this->gatherColumn($class, $idProperty, $table);
                                $columnName = $column->getQuotedName($this->platform);

                                // TODO: This seems rather hackish, can we optimize it?
                                $column->setAutoincrement(false);

                                $pkColumns[]           = $columnName;
                                $inheritedKeyColumns[] = $columnName;
                            }
                        }

                        if (! empty($inheritedKeyColumns)) {
                            // Add a FK constraint on the ID column
                            $rootClass = $this->em->getClassMetadata($class->getRootClassName());

                            $table->addForeignKeyConstraint(
                                $rootClass->table->getQuotedQualifiedName($this->platform),
                                $inheritedKeyColumns,
                                $inheritedKeyColumns,
                                ['onDelete' => 'CASCADE']
                            );
                        }
                    }

                    $table->setPrimaryKey($pkColumns);

                    break;

                case InheritanceType::TABLE_PER_CLASS:
                    throw NotSupported::create();

                default:
                    $this->gatherColumns($class, $table);
                    $this->gatherRelationsSql($class, $table, $schema, $addedFks, $blacklistedFks);

                    break;
            }

            $pkColumns = [];

            foreach ($class->identifier as $identifierField) {
                $property = $class->getProperty($identifierField);

                if ($property instanceof FieldMetadata) {
                    $pkColumns[] = $this->platform->quoteIdentifier($property->getColumnName());

                    continue;
                }

                if ($property instanceof ToOneAssociationMetadata) {
                    foreach ($property->getJoinColumns() as $joinColumn) {
                        $pkColumns[] = $this->platform->quoteIdentifier($joinColumn->getColumnName());
                    }
                }
            }

            if (! $table->hasIndex('primary')) {
                $table->setPrimaryKey($pkColumns);
            }

            // there can be unique indexes automatically created for join column
            // if join column is also primary key we should keep only primary key on this column
            // so, remove indexes overruled by primary key
            $primaryKey = $table->getIndex('primary');

            foreach ($table->getIndexes() as $idxKey => $existingIndex) {
                if ($primaryKey->overrules($existingIndex)) {
                    $table->dropIndex($idxKey);
                }
            }

            if ($class->table->getIndexes()) {
                foreach ($class->table->getIndexes() as $indexName => $indexData) {
                    $indexName = is_numeric($indexName) ? null : $indexName;
                    $index     = new Index($indexName, $indexData['columns'], $indexData['unique'], $indexData['flags'], $indexData['options']);

                    foreach ($table->getIndexes() as $tableIndexName => $tableIndex) {
                        if ($tableIndex->isFullfilledBy($index)) {
                            $table->dropIndex($tableIndexName);
                            break;
                        }
                    }

                    if ($indexData['unique']) {
                        $table->addUniqueIndex($indexData['columns'], $indexName, $indexData['options']);
                    } else {
                        $table->addIndex($indexData['columns'], $indexName, $indexData['flags'], $indexData['options']);
                    }
                }
            }

            if ($class->table->getUniqueConstraints()) {
                foreach ($class->table->getUniqueConstraints() as $indexName => $indexData) {
                    $indexName = is_numeric($indexName) ? null : $indexName;
                    $uniqIndex = new Index($indexName, $indexData['columns'], true, false, $indexData['flags'], $indexData['options']);

                    foreach ($table->getIndexes() as $tableIndexName => $tableIndex) {
                        if ($tableIndex->isFullfilledBy($uniqIndex)) {
                            $table->dropIndex($tableIndexName);
                            break;
                        }
                    }

                    $table->addUniqueConstraint($indexData['columns'], $indexName, $indexData['flags'], $indexData['options']);
                }
            }

            if ($class->table->getOptions()) {
                foreach ($class->table->getOptions() as $key => $val) {
                    $table->addOption($key, $val);
                }
            }

            $processedClasses[$class->getClassName()] = true;

            foreach ($class->getDeclaredPropertiesIterator() as $property) {
                if (! $property instanceof FieldMetadata
                    || ! $property->hasValueGenerator()
                    || $property->getValueGenerator()->getType() !== GeneratorType::SEQUENCE
                    || $class->getClassName() !== $class->getRootClassName()) {
                    continue;
                }

                $quotedName = $this->platform->quoteIdentifier($property->getValueGenerator()->getDefinition()['sequenceName']);

                if (! $schema->hasSequence($quotedName)) {
                    $schema->createSequence($quotedName, $property->getValueGenerator()->getDefinition()['allocationSize']);
                }
            }

            if ($eventManager->hasListeners(ToolEvents::postGenerateSchemaTable)) {
                $eventManager->dispatchEvent(
                    ToolEvents::postGenerateSchemaTable,
                    new GenerateSchemaTableEventArgs($class, $schema, $table)
                );
            }
        }

        if (! $this->platform->supportsSchemas() && ! $this->platform->canEmulateSchemas()) {
            $schema->visit(new RemoveNamespacedAssets());
        }

        if ($eventManager->hasListeners(ToolEvents::postGenerateSchema)) {
            $eventManager->dispatchEvent(
                ToolEvents::postGenerateSchema,
                new GenerateSchemaEventArgs($this->em, $schema)
            );
        }

        return $schema;
    }
146641
public function setClassAttr($classes)
    {
        if (is_array($classes)) {
            $classes = implode(' ', $classes);
        }

        $this->classAttr = $classes;

        return $this;
    }
1021419
protected function discoverClasses(array $namespaces) : array {
    $classes = [];

    foreach ($namespaces as $namespace => $namespace_directories) {
      $namespace_directories = array_filter($namespace_directories, function ($dir) {
        return is_dir($dir);
      });
      foreach ($namespace_directories as $namespace_directory) {
        $finder = $this->createFinder()
          ->files()
          ->name('*.php')
          ->in($namespace_directory)
          ->path($this->subdir);
        foreach ($finder as $file) {
          // Remove the namespace directory from the full file path.
          $sub_path = substr($file->getPath(), strlen($namespace_directory));
          if (!empty($sub_path)) {
            $sub_path = substr($sub_path, 1);
            $sub_path = str_replace('/', '\\', $sub_path);
            $sub_path .= '\\';
            $classes[] = $namespace . $sub_path . $file->getBasename('.php');
          }
        }
      }
    }

    return $classes;
  }
856872
public function findClasses()
    {
        $files = $this->getFiles($this->searchPath);

        // if class are not loaded they will ne be caught by "declared_classes"
        $this->loadFiles($files);

        return $this->identifyClasses();
    }
525191
public function getAccessibleRoles(array $roles)
    {
        $accessibleRoles = $roles;
        foreach ($roles as $role) {
            /**
             * @var $role Role
             */
            if (isset($this->map[$role->getRole()])) {
                foreach ($this->map[$role->getRole()] as $r) {
                    $accessibleRoles[] = new Role($r);
                }
            }
        }

        return $accessibleRoles;
    }
1144979
protected function classes()
    {
        list($items, $pattern) = array(array(), '/\\.[^.\\s]{3,4}$/');

        $files = glob($this->commands . '/*.php');

        $path = strlen($this->commands . DIRECTORY_SEPARATOR);

        foreach ((array) $files as $file) {
            $substring = substr($file, $path);

            $class = preg_replace($pattern, '', $substring);

            $class = $this->namespace . '\\' . $class;

            $reflection = new \ReflectionClass($class);

            $reflection->isAbstract() || $items[] = $class;
        }

        return $items;
    }
12987
protected function supportClasses($subject, array $classes) {
        foreach ($classes as $supportedClass) {
            if ($subject instanceof $supportedClass) {
                return true;
            }
        }

        return false;
    }
311481
public function addExtraClasses($classes)
    {
        if (!is_array($classes)) {
            $classes = explode(" ", $classes);
        }

        $this->extra_classes = array_merge(
            $this->extra_classes,
            $classes
        );

        return $this;
    }