Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • Address
  • Attachment
  • Body
  • Header
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Jyxo PHP Library
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file license.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * https://github.com/jyxo/php/blob/master/license.txt
 12:  */
 13: 
 14: namespace Jyxo\Mail\Email;
 15: 
 16: /**
 17:  * Email address.
 18:  *
 19:  * @category Jyxo
 20:  * @package Jyxo\Mail
 21:  * @subpackage Email
 22:  * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
 23:  * @license https://github.com/jyxo/php/blob/master/license.txt
 24:  * @author Jaroslav HanslĂ­k
 25:  */
 26: class Address extends \Jyxo\Spl\Object
 27: {
 28:     /**
 29:      * Email address.
 30:      *
 31:      * @var string
 32:      */
 33:     private $email = '';
 34: 
 35:     /**
 36:      * Name.
 37:      *
 38:      * @var string
 39:      */
 40:     private $name = '';
 41: 
 42:     /**
 43:      * Creates an address.
 44:      *
 45:      * @param string $email Email
 46:      * @param string $name Name
 47:      * @throws \InvalidArgumentException If an invalid email address was provided
 48:      */
 49:     public function __construct($email, $name = '')
 50:     {
 51:         $this->setEmail($email);
 52:         $this->setName($name);
 53:     }
 54: 
 55:     /**
 56:      * Returns email address.
 57:      *
 58:      * @return string
 59:      */
 60:     public function getEmail()
 61:     {
 62:         return $this->email;
 63:     }
 64: 
 65:     /**
 66:      * Sets email address.
 67:      *
 68:      * @param string $email Email address
 69:      * @return \Jyxo\Mail\Email\Address
 70:      * @throws \InvalidArgumentException If an invalid email address was provided
 71:      */
 72:     public function setEmail($email)
 73:     {
 74:         $email = trim((string) $email);
 75: 
 76:         // Validity check
 77:         if (!\Jyxo\Input\Validator\IsEmail::validate($email)) {
 78:             throw new \InvalidArgumentException(sprintf('Invalid email address %s.', $email));
 79:         }
 80: 
 81:         $this->email = $email;
 82: 
 83:         return $this;
 84:     }
 85: 
 86:     /**
 87:      * Returns name.
 88:      *
 89:      * @return string
 90:      */
 91:     public function getName()
 92:     {
 93:         return $this->name;
 94:     }
 95: 
 96:     /**
 97:      * Sets name.
 98:      *
 99:      * @param string $name Name
100:      * @return \Jyxo\Mail\Email\Address
101:      */
102:     public function setName($name)
103:     {
104:         $this->name = trim((string) $name);
105: 
106:         return $this;
107:     }
108: }
109: 
Jyxo PHP Library API documentation generated by ApiGen 2.3.0