Horde_Icalendar::getAttribute PHP Метод

getAttribute() публичный Метод

Get the value of an attribute.
public getAttribute ( string $name, boolean $params = false ) : mixed
$name string The name of the attribute.
$params boolean Return the parameters for this attribute instead of its value.
Результат mixed (string) The value of the attribute. (array) The parameters for the attribute or multiple values for an attribute.
    public function getAttribute($name, $params = false)
    {
        if ($name == 'VERSION') {
            return $this->_version;
        }
        $result = array();
        foreach ($this->_attributes as $attribute) {
            if ($attribute['name'] == $name) {
                $result[] = $params ? $attribute['params'] : $attribute['value'];
            }
        }
        if (!count($result)) {
            throw new Horde_Icalendar_Exception('Attribute "' . $name . '" Not Found');
        } elseif (count($result) == 1 && !$params) {
            return $result[0];
        }
        return $result;
    }

Usage Example

Пример #1
0
 /**
  * @requires extension bcmath
  */
 public function testvTodo()
 {
     $tnef = Horde_Compress::factory('Tnef');
     $mime = Horde_Mime_Part::parseMessage(file_get_contents(__DIR__ . '/fixtures/tnef_task.eml'));
     try {
         $tnef_data = $tnef->decompress($mime->getPart(2)->getContents());
     } catch (Horde_Mapi_Exception $e) {
         $this->markTestSkipped('Horde_Mapi is not available');
     } catch (Horde_Compress_Exception $e) {
         var_dump($e);
     }
     // Test the generated iCalendar.
     $iCal = new Horde_Icalendar();
     if (!$iCal->parsevCalendar($tnef_data[0]['stream'])) {
         throw new Horde_Compress_Exception(_("There was an error importing the iCalendar data."));
     }
     $this->assertEquals($iCal->getAttribute('METHOD'), 'REQUEST');
     $components = $iCal->getComponents();
     if (count($components) == 0) {
         throw new Horde_Compress_Exception(_("No iCalendar data was found."));
     }
     $vTodo = current($components);
     $this->assertEquals($vTodo->getAttribute('SUMMARY'), 'Test Task');
     $this->assertEquals($vTodo->getAttribute('UID'), 'EDF71E6FA6FB69A79D79FE1D6DCDBBD300000000DFD9B6FB');
     $this->assertEquals($vTodo->getAttribute('ATTENDEE'), 'Michael Rubinsky <*****@*****.**>');
     $params = $vTodo->getAttribute('ATTENDEE', true);
     if (!$params) {
         throw new Horde_Compress_Exception('Could not find expected parameters.');
     }
     $this->assertEquals($params[0]['ROLE'], 'REQ-PARTICIPANT');
     $this->assertEquals($vTodo->getAttribute('ORGANIZER'), 'mailto: [email protected]');
 }
All Usage Examples Of Horde_Icalendar::getAttribute