Papi_Core_Conditional_Rule::get_source PHP Method

get_source() public method

Get the source value.
public get_source ( ) : mixed
return mixed
    public function get_source()
    {
        if (is_callable($this->source)) {
            return call_user_func_array($this->source, [$this->slug]);
        }
        if (is_string($this->source) && strpos($this->source, '#') !== false) {
            $source = explode('#', $this->source);
            if (empty($source[0]) || empty($source[1])) {
                return $this->source;
            }
            $source[0] = new $source[0]();
            if (method_exists($source[0], $source[1])) {
                return call_user_func_array($source, [$this->slug]);
            }
            return;
        }
        return $this->source;
    }

Usage Example

 /**
  * Get property value.
  *
  * @param  Papi_Core_Conditional_Rule $rule
  *
  * @return mixed
  */
 private function get_value(Papi_Core_Conditional_Rule $rule)
 {
     if (papi_doing_ajax()) {
         $source = $rule->get_source();
         $meta_id = papi_get_meta_id();
         $entry_type = papi_get_entry_type_by_meta_id($meta_id);
         if (!papi_is_empty($source) && $entry_type instanceof Papi_Entry_Type !== false) {
             if (papi_is_property($entry_type->get_property($rule->slug))) {
                 return $this->get_deep_value($rule->slug, $source);
             }
         }
     }
     if (!papi_is_empty($rule->get_source())) {
         return $this->get_deep_value($rule->slug, $rule->get_source());
     }
     $slug = $rule->get_field_slug();
     $type = papi_get_meta_type();
     $value = papi_get_field($slug, null, $type);
     return $this->get_deep_value($slug, $value);
 }
All Usage Examples Of Papi_Core_Conditional_Rule::get_source