__construct() public method

Initializes a new ArrayCollection.
public __construct ( array $elements = [] )
$elements array
Example #1
0
 /**
  * Taxonomy constructor.
  *
  * @param array          $elements
  * @param MetadataDriver $metadata
  */
 public function __construct(array $elements = [], MetadataDriver $metadata = null)
 {
     parent::__construct($elements);
     if ($metadata) {
         $this->config = $metadata->getTaxonomyConfig();
     }
 }
Example #2
0
 public function __construct(array $elements = [])
 {
     foreach ($elements as $element) {
         $this->validate($element);
     }
     parent::__construct($elements);
 }
Example #3
0
 public function __construct(array $array, array $config = NULL)
 {
     if ($config) {
         $this->set('config', new DoctineArrayCollection($config));
     }
     parent::__construct($array);
 }
 /**
  * Constructs a Route object.
  */
 public function __construct($path, array $item)
 {
     $this->path = new PathUtility($path);
     // Merge in hook_menu() defaults to normalize things.
     $item += ['title callback' => 't', 'title arguments' => [], 'access callback' => 'user_access', 'access arguments' => [], 'page arguments' => [], 'type' => 'MENU_NORMAL_ITEM'];
     parent::__construct($item);
 }
 /**
  * @param array $elements
  * @param null  $page
  * @param int   $rpp
  * @param null  $total
  */
 public function __construct(array $elements = [], $page = null, $rpp = 10, $total = null)
 {
     $this->page = $page;
     $this->rpp = $rpp;
     $this->total = $total;
     parent::__construct($elements);
 }
Example #6
0
 /**
  * Constructor
  *
  * @param array           $elements
  * @param ArrayCollection $received
  * @param Basket          $basket
  * @param Boolean         $flatten
  */
 public function __construct(array $elements, ArrayCollection $received, Basket $basket = null, $flatten = self::FLATTEN_NO)
 {
     parent::__construct($elements);
     $this->received = $received;
     $this->basket = $basket;
     $this->isSingleStory = $flatten !== self::FLATTEN_YES && 1 === count($this) && $this->first()->isStory();
     if (self::FLATTEN_NO !== $flatten) {
         $to_remove = [];
         foreach ($this as $key => $record) {
             if ($record->isStory()) {
                 if (self::FLATTEN_YES === $flatten) {
                     $to_remove[] = $key;
                 }
                 foreach ($record->get_children() as $child) {
                     $this->set($child->get_serialize_key(), $child);
                 }
             }
         }
         foreach ($to_remove as $key) {
             $this->remove($key);
         }
     }
     $i = 0;
     $records = $this->toArray();
     array_walk($records, function ($record) use(&$i) {
         $record->setNumber($i++);
     });
 }
 public function __construct(array $elements = array())
 {
     parent::__construct();
     foreach ($elements as $element) {
         $this->add($element);
     }
 }
 public function __construct(array $elements = array(), $offset, $limit, $totalCount)
 {
     $this->offset = (int) $offset;
     $this->limit = (int) $limit;
     $this->totalCount = (int) $totalCount;
     parent::__construct($elements);
 }
Example #9
0
 public function __construct(array $days = [])
 {
     parent::__construct();
     foreach ($days as $day) {
         $this->addDay($day);
     }
 }
Example #10
0
 /**
  * Initializes a new Result.
  *
  * @param Query   $query
  * @param array   $elements
  * @param integer $recordsCount
  */
 public function __construct(Query $query, array $elements = array(), $recordsCount = 0)
 {
     $this->query = $query;
     $this->recordsCount = $recordsCount;
     parent::__construct($elements);
     $this->count = $this->count();
     $this->elements = $elements;
 }
Example #11
0
 /**
  * Initializes a new ModulesCollection.
  *
  * @param Module[] $modules
  */
 public function __construct(array $modules = array())
 {
     $constructed = array();
     foreach ($modules as $module) {
         $constructed[$module->getIdentifier()] = $module;
     }
     parent::__construct($constructed);
 }
Example #12
0
 /**
  * Initializes a new ArrayCollection.
  *
  * @param array $elements
  * @param bool  $hasBeenRandomized
  */
 public function __construct(array $elements = array(), $hasBeenRandomized = false)
 {
     parent::__construct();
     foreach ($elements as $element) {
         $this->add($element);
     }
     $this->hasBeenRandomized = $hasBeenRandomized;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(array $elements = [])
 {
     parent::__construct($elements);
     $this->keys = [];
     foreach ($elements as $element) {
         $this->keys[(string) $element] = true;
     }
 }
Example #14
0
 public function __construct(array $elements = array())
 {
     parent::__construct($elements);
     $this->add(new EqualsSearchOperator());
     $this->add(new LikeSearchOperator());
     $this->add(new LikeApproxSearchOperator());
     $this->add(new GreaterThanSearchOperator());
     $this->add(new LowerThanSearchOperator());
 }
 public function __construct(array $elements)
 {
     foreach ($elements as $element) {
         if (!$element instanceof ClientAccount) {
             throw new \InvalidArgumentException('Elements must be instance of ClientAccount.');
         }
     }
     parent::__construct(array_values($elements));
 }
 /**
  * Initializes a new ArrayCollection.
  *
  * @param array $elements
  */
 public function __construct()
 {
     //$this->featuresManager = new FeaturesManager();
     $this->mediaHandlersManager = new MediaHandlersManager();
     //
     $this->mediaHandlers = $this->mediaHandlersManager->getMediaHandlers();
     $elements = [];
     parent::__construct($elements);
 }
 /**
  * @param array $elements
  */
 public function __construct(array $elements = [])
 {
     $definitions = [];
     foreach ($elements as $definitionFactory) {
         $definition = $this->createDefinition($definitionFactory);
         $definitions[] = $definition;
     }
     parent::__construct($definitions);
 }
 /**
  * Initializes a new ArrayCollection.
  *
  * @param array $elements
  */
 public function __construct(array $elements = [])
 {
     parent::__construct();
     if (count($elements)) {
         foreach ($elements as $element) {
             $this->add($element);
         }
     }
 }
 /**
  * Initializes a new ArrayCollection.
  *
  * @param array $elements
  */
 public function __construct()
 {
     $elements = [];
     parent::__construct($elements);
     $featuresManager = new FeaturesManager();
     $features = $featuresManager->getFeatures();
     foreach ($features as $featureAlias) {
         $this->set($featureAlias, $featuresManager->getFeature($featureAlias));
     }
 }
Example #20
0
 /**
  * Initializes a new Collection.
  *
  * @param array $elements
  *
  * @throws \UnexpectedValueException
  */
 public function __construct(array $collection = [], $type = null)
 {
     $this->type = $type;
     foreach ($collection as $item) {
         if (!$this->checkType($item)) {
             throw new \UnexpectedValueException('Mixed types in array');
         }
     }
     parent::__construct($collection);
 }
 /**
  * {@inheritdoc}
  */
 public function __construct(PathUtilityInterface $path, array $parameters, array $arguments = [])
 {
     parent::__construct();
     $this->path = $path;
     $this->_length = sizeof($path);
     while ($parameters) {
         $argument = $arguments ? array_shift($arguments) : ParameterBinding::NO_ARGUMENT;
         $this->addBinding(new ParameterBinding($path, array_shift($parameters), $argument));
     }
 }
 /**
  * @param array $elements
  */
 public function __construct(array $elements = array())
 {
     parent::__construct($elements);
     // if Collection was init with data already that is mean no lazy loading required
     $numArgs = func_num_args();
     if ($numArgs >= 1) {
         $this->isInit = true;
         $this->total = $this->count();
     }
 }
Example #23
0
 /**
  * @param Paginator|array $paginator
  */
 public function __construct($list)
 {
     if ($list instanceof Paginator) {
         $this->setPaginator($list);
         $list = $list->getIterator()->getArrayCopy();
     } elseif (!is_array($list)) {
         throw new \InvalidArgumentException(self::ERROR_LIST_TYPE);
     }
     parent::__construct($list);
 }
Example #24
0
 public function __construct($node = null)
 {
     $link = [];
     if (!is_null($node) && $node instanceof \DOMElement) {
         $link = ['href' => $node->getAttribute('href'), 'rel' => $node->getAttribute('rel')];
     } elseif (is_string($node)) {
         $link['href'] = $node;
     }
     $link['status'] = 0;
     parent::__construct($link);
 }
 /**
  * @param array $permissions
  * @throws \RuntimeException
  */
 public function __construct(array $permissions = array())
 {
     $constructed = array();
     foreach ($permissions as $permission) {
         if (!$permission instanceof Permission) {
             throw new \RuntimeException(sprintf('PermissionsCollection must contains only Permission objects (%s given)', gettype($permission)));
         }
         $constructed[$permission->getName()] = $permission;
     }
     parent::__construct($constructed);
 }
Example #26
0
 public function __construct(array $entities = [])
 {
     $this->entityClass = (string) $this->getEntityClass();
     if (!class_exists($this->entityClass)) {
         throw new CollectionException(sprintf('Class %s does not exist.', $this->entityClass));
     }
     foreach ($entities as $entity) {
         $this->checkInstanceOf($entity);
     }
     parent::__construct($entities);
 }
Example #27
0
 /**
  * Constructor
  *
  * @param String     $context
  * @param Resource[] $elements An array of Resource
  */
 public function __construct($context, array $elements, $temporary)
 {
     array_walk($elements, function ($element) {
         if (!$element instanceof Resource) {
             throw new InvalidArgumentException('ResourceCollection only accept Resource elements');
         }
     });
     $this->context = $context;
     $this->temporary = (bool) $temporary;
     parent::__construct($elements);
 }
Example #28
0
 /**
  * 构造方法
  */
 public function __construct(Request $request = null)
 {
     $request = $request ?: Request::createFromGlobals();
     $content = $request->getContent();
     try {
         $options = Serializer::parse($content);
     } catch (\InvalidArgumentException $e) {
         $options = array();
     }
     parent::__construct($options);
 }
Example #29
0
 /**
  * Constructor.
  *
  * Field must to be build like [manager name] => [method]
  *
  * Example:
  *  $this->users = new ArrayCollection($this, array(
  *    'entity'   => 'getUser',
  *    'document' => 'getUser'
  *  ));
  *
  * @param mixed $model
  * @param array $fields
  * @param array $elements (optional)
  */
 public function __construct($model, array $fields, array $elements = array())
 {
     parent::__construct();
     $this->model = $model;
     foreach ($fields as $managerName => $method) {
         $this->fields[sprintf('get%s', ucfirst($managerName))] = $method;
     }
     foreach ($elements as $element) {
         $this->add($element);
     }
 }
Example #30
0
 /**
  * 刷新用户 access_token
  */
 public function refresh()
 {
     $query = array('appid' => $this->appid, 'grant_type' => 'refresh_token', 'refresh_token' => $this['refresh_token']);
     $response = Http::request('GET', static::REFRESH)->withQuery($query)->send();
     if ($response['errcode'] != 0) {
         throw new \Exception($response['errmsg'], $response['errcode']);
     }
     // update new access_token from ArrayCollection
     parent::__construct($response->toArray());
     return $this;
 }