• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/orm/objectify/collection.php
  • Класс: BitrixMainORMObjectifyCollection
  • Вызов: Collection::add
public function add(EntityObject $object)
{
	// check object class
	if (!($object instanceof $this->_objectClass))
	{
		throw new ArgumentException(sprintf(
			'Invalid object class %s for %s collection, expected "%s".',
			get_class($object), get_class($this), $this->_objectClass
		));
	}

	$srPrimary = $this->sysGetPrimaryKey($object);

	if (!$object->sysHasPrimary())
	{
		// object is new and there is no primary yet
		$object->sysAddOnPrimarySetListener([$this, 'sysOnObjectPrimarySet']);
	}

	if (empty($this->_objects[$srPrimary])
		&& (!isset($this->_objectsChanges[$srPrimary]) || $this->_objectsChanges[$srPrimary] != static::OBJECT_REMOVED))
	{
		$this->_objects[$srPrimary] = $object;
		$this->_objectsChanges[$srPrimary] = static::OBJECT_ADDED;
	}
	elseif (isset($this->_objectsChanges[$srPrimary]) && $this->_objectsChanges[$srPrimary] == static::OBJECT_REMOVED)
	{
		// silent add for removed runtime
		$this->_objects[$srPrimary] = $object;

		unset($this->_objectsChanges[$srPrimary]);
		unset($this->_objectsRemoved[$srPrimary]);
	}
}