添加观察者
@param \SplObserver $observer
422899
function attach(\SplObserver $observer)
    {
        if ($this->_observers == null)
        {
            $this->_observers = new \SplObjectStorage();
        }
        $this->_observers->attach($observer);
    }
1230180
public function execute(Observer $observer)
    {
        /** @var Order $order */
        $order = $observer->getEvent()->getOrder();

        try {
            $this->salesEventHandler->store($order);
        } catch (\Exception $e) {
            $this->logger->warning('Emartech\\Emarsys\\Observers\\SalesOrderObserver: ' . $e->getMessage());
        }
    }
531721
public function attach(ObserverInterface $observer): SubjectInterface
   {
       if ($observer instanceof XHTMLTemplate) {
           parent::attach($observer);
       }
       return $this;
   }
234946
private function _loadObservers()
  {
    $class = $this->name();
    $name = self::_configName($class);
    $config = Config::getInstance($name);
    
    $this->_observers = $config->valueOf();
  }
1360559
public function addExportToBulkAction($observer)
    {
        $block = $observer->getBlock();
        if (
            $block instanceof Mage_Adminhtml_Block_Sales_Order_Grid &&
            Mage::helper('australia/clickandsend')->isClickAndSendEnabled()
        ) {
            $block->getMassactionBlock()->addItem('clickandsendexport', array(
                'label' => $block->__('Export to CSV (Click & Send)'),
                'url'   => $block->getUrl('*/australia_clickandsend/export')
            ));
        }
    }
432225
public function postApply(Varien_Event_Observer $observer)
    {
        $productIds = array();
        foreach ($this->_productIds as $productId) {
            $productIds[] = EcomDev_Varnish_Model_Processor_Product::TAG_PREFIX  . $productId;
        }

        // Run cleaning process separately if amount of stored tags too large
        $chunks = array_chunk(
            $productIds,
            500
        );

        foreach ($chunks as $tags) {
            Mage::getSingleton('ecomdev_varnish/connector')->banTags($tags);
        }

        $this->_productIds = array();
    }
1078314
public function attach($observer)
	{
		if (is_array($observer))
		{
			if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler']))
			{
				return;
			}

			// Make sure we haven't already attached this array as an observer
			foreach ($this->_observers as $check)
			{
				if (is_array($check) && $check['event'] == $observer['event'] && $check['handler'] == $observer['handler'])
				{
					return;
				}
			}

			$this->_observers[] = $observer;
			end($this->_observers);
			$methods = array($observer['event']);
		}
		else
		{
			if (!($observer instanceof JObserver))
			{
				return;
			}

			// Make sure we haven't already attached this object as an observer
			$class = get_class($observer);

			foreach ($this->_observers as $check)
			{
				if ($check instanceof $class)
				{
					return;
				}
			}

			$this->_observers[] = $observer;
			$methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin'));
		}

		$key = key($this->_observers);

		foreach ($methods as $method)
		{
			$method = strtolower($method);

			if (!isset($this->_methods[$method]))
			{
				$this->_methods[$method] = array();
			}

			$this->_methods[$method][] = $key;
		}
	}
983973
public void addSNIObserver(Consumer<SNIServerName> observer)
    {
        if (sniObservers == null)
        {
            sniObservers = new ArrayList<>();
        }
        sniObservers.add(observer);
    }
1055960
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $productCollection = $observer->getEvent()->getData('product_collection');
        $storeId           = $observer->getEvent()->getData('store_id');

        if (($productCollection instanceof \Magento\Catalog\Model\ResourceModel\Product\Collection) && $storeId) {
            $this->logEvent($productCollection, $storeId);
        }
    }
352902
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $additional = $observer->getAdditional();
        $conditions = (array) $additional->getConditions();
        $conditions = array_merge_recursive($conditions, [$this->getShopgateCondition()]);
        $additional->setConditions($conditions);

        return $this;
    }
597820
public function attach(ServerObserver $observer)
    {
        if ($this->state) {
            throw new \Error("Cannot attach observers after the server has started");
        }

        $this->observers->attach($observer);
    }
129286
public static void addObserver(TaskObserver<?> observer) {
		if(observer != null && tls.get().observers == null) {
			tls.get().observers = new ArrayList<TaskObserver<?>>();
		}
		tls.get().observers.add(observer);
	}
572980
@Override
    public void addObserver(final Observer<S, T> observer) {
        synchronized (OBSERVER_LOCK) {
            if (observers.contains(observer)) {
                LOGGER.warn("Skip observer registration. Observer[" + observer + "] is already registered!");
                return;
            }
            observers.add(observer);
        }
    }
382907
public function execute(Observer $observer) {
        
        // Get a potential 3D Secure redirect url from session
        $redirectUrl = $this->session->get3DSRedirect();

        // Get the card id charge flag
        $isCardIdCharge = $this->session->getCardIdChargeFlag() == 'cardIdCharge';

        // Handle a 3D Secure redirection if needed
        if ($this->isUrl($redirectUrl)) {

            // Exit to force redirection in case of card id charge
            if ($isCardIdCharge) {
                // Unset the session variable
                $this->session->unsCardIdChargeFlag();
                exit();
            }
        }
    }
332312
public function execute(EventObserver $observer)
    {
        if (!$this->config->isDisplayInMenu()) {
            return;
        }
        /** @var \Magento\Framework\Data\Tree\Node $menu */
        $menu = $observer->getData('menu');

        $categories = $this->categoryCollectionFactory->create()
            ->addAttributeToSelect(['name', 'url_key'])
            ->excludeRoot()
            ->addVisibilityFilter();

        $tree = $categories->getTree();

        $rootNode = new TreeNode(
            [
                'id'   => 'blog-node-root',
                'name' => $this->config->getMenuTitle(),
                'url'  => $this->config->getBaseUrl()
            ],
            'id',
            $menu->getTree(),
            null
        );
        //@todo find correct way to add class
        if ($menu->getPositionClass()) {
            $menu->setPositionClass('blog-mx' . $menu->getPositionClass());
        } else {
            $menu->setPositionClass('blog-mx nav' . $menu->getPositionClass());
        }
        $menu->addChild($rootNode);

        foreach ($tree as $category) {
            if (isset($tree[$category->getParentId()])) {
                $parentNode = $tree[$category->getParentId()]->getData('node');
            } else {
                $parentNode = $rootNode;
            }

            $node = new TreeNode(
                [
                    'id'   => 'blog-node-' . $category->getId(),
                    'name' => $category->getName(),
                    'url'  => $category->getUrl()
                ],
                'id',
                $menu->getTree(),
                $parentNode
            );

            if ($parentNode) {
                $parentNode->addChild($node);
            } else {
                $menu->addChild($node);
            }

            $category->setData('node', $node);
        }
    }
967387
public function handle(AttributeCodeAndValueAwareObserverInterface $observer)
    {

        // set the observer
        $this->setObserver($observer);

        // replace the passed attribute value into the page layout
        return $this->getSubject()->getPageLayoutByValue($observer->getAttributeValue());
    }
342029
public function notify($state = null)
	{
		assert($state === null || is_int($state));
		$this->_state = intval($state) ?: $this->_state;

		/** @var \SplObserver $observer */
		foreach ($this->_observers as $observer)
		{
			$observer->update($this);
		}
	}