Set Class Instances

Load each Class instance and store in $instances[]
975946
protected function setClassesToRun()
    {
        foreach ($this->listOfFiles as $filename => $file) {
            // Exclude non-PHP files
            if (!Utils::isFilePhp($filename)) {
                continue;
            }

            // Exclude non-Controller classes
            if (!Utils::doesFileContain($filename, 'extends Controller')) {
                continue;
            }

            // Set the classes to run
            $this->classesToRun[] = $this->namespace . '\\' . pathinfo($filename, PATHINFO_FILENAME);
        }
    }
1066211
def load_many(self, fobjs=None):
        """"""
        if fobjs is not None:
            # tolerance
            if not hasattr(fobjs, "__iter__"):
                fobjs = [fobjs]

            for index, (fobj, page) in enumerate(zip(fobjs, self.pages)):
                if fobj is None:
                    continue
                elif isinstance(fobj, ft.DataFile):
                    self.load(fobj, index)
                elif isinstance(fobj, str):
                    self.load_filename(fobj, index)
                else:
                    raise TypeError("Invalid object of class '{}'".format(fobj.__class__.__name__))
368398
public static function validateInstances($instances, $group = "") {
		if (sizeof ( $instances ) > 0) {
			$instance = current ( $instances );
			$class = get_class ( $instance );
			$cache = self::getClassCacheValidators ( $class, $group );
			if ($cache === false) {
				$members = self::fetch ( $class );
				self::initInstancesValidators ( $instance, $members, $group );
				$cache = self::$instanceValidators [$class];
			}
			return self::validateInstances_ ( $instances, $cache );
		}
		return [ ];
	}
316963
public function registerArray(array $instances)
    {
        foreach ($instances as $name => $instance) {
            $this->register($name, $instance);
        }

        return $this;
    }
667831
def each_instance( namespace_or_objectpath, classname = nil )
    op = if namespace_or_objectpath.is_a? Openwsman::ObjectPath
      namespace_or_objectpath
    else
      objectpath namespace_or_objectpath, classname
    end
    @options.flags = Openwsman::FLAG_ENUMERATION_OPTIMIZATION
    @options.max_elements = 999
    uri = epr_uri_for op.namespace, op.classname
    result = @client.enumerate( @options, nil, uri )
    loop do
      if _handle_fault @client, result
        break
      end
      items = result.Items rescue nil
      if items
        items.each do |inst|
          yield Wbem::Instance.new(self, uri, inst)
        end
      end
      context = result.context
      break unless context
      result = @client.pull( @options, nil, uri, context )
    end
  end
551616
protected function loadChildClasses()
    {
        foreach ($this->rawOptions as &$option) {
            if (is_array($option)
                && array_key_exists('class', $option)
                && class_exists($option['class'])
            ) {
                $classLoader = new ClassLoader($option);
                $option = $classLoader->load();
            }
        }
    }
900696
private static function createInstance($classname, array $arguments = array())
    {
        $reflection_obj = new ReflectionClass($classname);
        if ($reflection_obj->getMethod('__construct')->isPublic()) {
            self::$_instances[ $classname ] = call_user_func_array(array($reflection_obj, 'newInstance'), $arguments);
            if (
                method_exists(self::$_instances[ $classname ], 'init') &&
                is_callable(array(self::$_instances[ $classname ], 'init'))
            ) {
                self::$_instances[ $classname ]->init();
            }
        } else {
            self::$_instances[ $classname ] = new $classname;
            if (
                method_exists(self::$_instances[ $classname ], 'init') &&
                is_callable(array(self::$_instances[ $classname ], 'init'))
            ) {
                call_user_func_array(array(self::$_instances[ $classname ], 'init'), $arguments);
            }
        }
    }
919033
@Override
    public Set<Object> getInstances() {
        Set<Object> set = new HashSet<>();
        ClassLoader cl = Thread.currentThread().getContextClassLoader();

        Consumer<JsonArray> reader = array -> {
            if (array != null && array.size() > 0) {
                for (int i = 0; i < array.size(); i++) {
                    try {
                        Class<?> clazz = cl.loadClass(array.getString(i));
                        set.add(clazz.newInstance());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        JsonArray binders = config.getJsonArray(CONFIG_BINDERS, null);
        JsonArray instances = config.getJsonArray(CONFIG_INSTANCES, null);

        reader.accept(binders);
        reader.accept(instances);

        return set;
    }
294790
public static function instances()
    {
        $all = [];
        foreach (static::getNames() as $name => $val) {
            $all[] = new static($name, $val);
        }
        return $all;
    }
368993
public function setClasses($classes)
    {
        if (!is_array($classes)) {
            $classes = $classes ? array($classes) : array();
        }
        $this->modelClasses = $classes;
    }
586428
private void autoLoadClasses()
	{
		Set<ASMData> classes = ImmutableSortedSet.copyOf(	Ordering.natural().onResultOf(ASMData::getClassName),
															asmDataTable.getAll(AutoLoad.class.getName()));

		Set<ASMData> clientClasses = asmDataTable.getAll(SideOnly.class.getName());

		for (ASMData data : classes)
		{
			try
			{
				//don't load client classes on server.
				if (!isClient() && isClientClass(data.getClassName(), clientClasses))
					continue;

				Class<?> clazz = Class.forName(data.getClassName());
				AutoLoad anno = clazz.getAnnotation(AutoLoad.class);
				if (anno.value())
					clazz.newInstance();
			}
			catch (Exception e)
			{
				MalisisCore.log.error("Could not autoload {}.", data.getClassName(), e);
			}
		}
	}
397649
protected function setup_instance() {
		switch ( $this->wp_type ) {
			case 'post':
				$wp_post = get_post( $this->get_id() );
				if ( ! is_null( $wp_post ) && get_post_type( $wp_post->ID ) === $this->object_type ) {
					$this->set_instance( $wp_post );
				}
				break;

			case 'term':
				$wp_term = get_term( $this->get_id(), $this->object_type );
				if ( ! is_null( $wp_term ) && ! is_wp_error( $wp_term ) ) {
					$this->set_instance( $wp_term );
				}
				break;
		}
	}
1161212
public static function setInstance($instance)
    {
        if ($instance === null) {
            unset(Yii::getApp()->loadedModules[static::class]);
        } else {
            Yii::getApp()->loadedModules[\get_class($instance)] = $instance;
        }
    }
1036009
function load($data = [])
    {
        foreach ($this as $k => $v) {
            if ($k == 'table' || $k == 'where') {
                continue;
            }
            if (isset($data[$k])) {
                $this->$k = $data[$k];
            }
        }
    }
489399
public static function initialise()
		{
		// Create the class index for autoloading or including
		$paths = array(dirname(__FILE__));
		while (list($i, $path) = each($paths))
			{
			$subDirectorys = glob($path . "*", GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
			if (is_array($subDirectorys))
				{
				foreach ($subDirectorys as $subDirectory)
					{
					$paths[] = $subDirectory;
					}
				}
			$files = glob($path . "*.php", 0);
			if (is_array($files))
				{
				foreach ($files as $file)
					{
					$class = substr(basename($file), 0, -4);
					self::$classIndex[$class] = $file;
					}
				}
			}
		krsort(self::$classIndex);
		// Only use autoloading if spl_autoload_register() is available and no __autoload() is defined (because 
		// __autoload() breaks if spl_autoload_register() is used. 
		if (function_exists("spl_autoload_register") && !is_callable("__autoload"))
			{
			spl_autoload_register(array(__CLASS__, "autoload"));
			}
		// Otherwise include all class files
		else
			{
			foreach (self::$classIndex as $class => $file)
				{
				if (!class_exists($class))
					{
					require_once($file);
					}
				}
			}
		}
1218770
protected function get_classes( $dir, $instanceof, $return_instance = true ) {
		foreach ( $this->get_class_settings( $dir ) as $class_setting ) {
			$instance = $this->get_class_instance( $class_setting, $instanceof );
			if ( false !== $instance ) {
				if ( $return_instance ) {
					yield $instance;
				} else {
					yield $class_setting;
				}
			}
		}
	}
220125
protected function load() {

        // The instance constructor could be already loaded with the full course object. Using shortname
        // because it is a required course field.
        if (empty($this->course->shortname)) {
            $this->course = get_course($this->course->id);
        }

        $this->coursecontext = $this->get_context();

        $this->now = time();

        // Get the course users, including users assigned to student and teacher roles at an higher context.
        $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_analytics', 'rolearchetypes');

        // Flag the instance as loaded.
        $this->loaded = true;

        if (!$studentroles = $cache->get('student')) {
            $studentroles = array_keys(get_archetype_roles('student'));
            $cache->set('student', $studentroles);
        }
        $this->studentids = $this->get_user_ids($studentroles);

        if (!$teacherroles = $cache->get('teacher')) {
            $teacherroles = array_keys(get_archetype_roles('editingteacher') + get_archetype_roles('teacher'));
            $cache->set('teacher', $teacherroles);
        }
        $this->teacherids = $this->get_user_ids($teacherroles);
    }