Sokil\Mongo\Structure::get PHP Method

get() public method

public get ( $selector )
    public function get($selector)
    {
        if (false === strpos($selector, '.')) {
            return isset($this->data[$selector]) ? $this->data[$selector] : null;
        }
        $value = $this->data;
        foreach (explode('.', $selector) as $field) {
            if (!isset($value[$field])) {
                return null;
            }
            $value = $value[$field];
        }
        return $value;
    }

Usage Example

Example #1
0
 public function validateField(Structure $document, $fieldName, array $params)
 {
     if (!$document->get($fieldName)) {
         return;
     }
     if ($document->get($fieldName) !== $params['to']) {
         return;
     }
     if (!isset($params['message'])) {
         $params['message'] = 'Field "' . $fieldName . '" must be equals to "' . $params['to'] . '" in model ' . get_called_class();
     }
     $document->addError($fieldName, $this->getName(), $params['message']);
 }
All Usage Examples Of Sokil\Mongo\Structure::get