Skip to content
Snippets Groups Projects
Select Git revision
  • cac1b8c84eef9d07ec7691509b46192459a09660
  • master default protected
  • 1.6.4
  • 1.6.3
  • 1.6.2
  • 1.6.1
  • 1.6.0
  • 1.5.0
  • 1.4.0
  • 1.3.1
  • 1.3.0
  • 1.3.0-beta1
  • 1.2.1
  • 1.2.0
  • 1.2.0-beta5
  • 1.2.0-beta4
  • 1.2.0-beta3
  • 1.2.0-beta2
  • 1.2.0-beta1
  • 1.1.0
  • 1.0.0
21 results

GetParametersDisplayDecision.php

Blame
  • GetParametersDisplayDecision.php 958 B
    <?php
    
    namespace WPDesk\RepositoryRating\DisplayStrategy;
    
    /**
     * DisplayDecision based on GET parameters.
     */
    class GetParametersDisplayDecision implements DisplayDecision {
    
    	/**
    	 * Whether to show beacon on the page or not. Array of arrays with condition for _GET.
    	 * Inner arrays mean AND, outer arrays mean OR conditions.
    	 *
    	 * ie. [ [ ... and ... and ... ] or [ ... and ... and ... ] or ... ]
    	 *
    	 * @var array
    	 */
    	private $conditions;
    
    	public function __construct( array $conditions ) {
    		$this->conditions = $conditions;
    	}
    
    	/**
    	 * Should Beacon be visible?
    	 *
    	 * @return bool
    	 */
    	public function should_display(): bool {
    		foreach ( $this->conditions as $or_conditions ) {
    			$display = true;
    			foreach ( $or_conditions as $parameter => $value ) {
    				if ( ! isset( $_GET[ $parameter ] ) || $_GET[ $parameter ] !== $value ) {
    					$display = false;
    				}
    			}
    			if ( $display ) {
    
    				return $display;
    			}
    		}
    
    		return false;
    	}
    
    }