forked from Wavyzz/dolibarr
swiftmailer
This commit is contained in:
@@ -80,14 +80,16 @@ class CMailFile
|
||||
var $atleastoneimage=0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
|
||||
var $html_images=array();
|
||||
var $images_encoded=array();
|
||||
var $image_types = array('gif' => 'image/gif',
|
||||
var $image_types = array(
|
||||
'gif' => 'image/gif',
|
||||
'jpg' => 'image/jpeg',
|
||||
'jpeg' => 'image/jpeg',
|
||||
'jpe' => 'image/jpeg',
|
||||
'bmp' => 'image/bmp',
|
||||
'png' => 'image/png',
|
||||
'tif' => 'image/tiff',
|
||||
'tiff' => 'image/tiff');
|
||||
'tiff' => 'image/tiff',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
@@ -395,9 +397,21 @@ class CMailFile
|
||||
|
||||
$host = dol_getprefix('email');
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/EmailParser.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Warning/Warning.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Warning/LocalTooLong.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Parser/Parser.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Parser/DomainPart.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Parser/LocalPart.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Validation/EmailValidation.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/Validation/RFCValidation.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/EmailLexer.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/egulias/email-validator/EmailValidator/EmailValidator.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
|
||||
// Create the message
|
||||
$this->message = Swift_Message::newInstance();
|
||||
//$this->message = Swift_Message::newInstance();
|
||||
$this->message = new Swift_Message();
|
||||
|
||||
// Adding a trackid header to a message
|
||||
$headers = $this->message->getHeaders();
|
||||
@@ -449,11 +463,11 @@ class CMailFile
|
||||
if ($this->msgishtml) {
|
||||
$this->message->setBody($msg,'text/html');
|
||||
// And optionally an alternative body
|
||||
//$this->message->addPart('Here is the message itself', 'text/plain');
|
||||
$this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain');
|
||||
} else {
|
||||
$this->message->setBody($msg,'text/plain');
|
||||
// And optionally an alternative body
|
||||
//$this->message->addPart('<q>Here is the message itself</q>', 'text/html');
|
||||
$this->message->addPart($msg, 'text/html');
|
||||
}
|
||||
|
||||
if ($this->atleastonefile)
|
||||
@@ -491,7 +505,7 @@ class CMailFile
|
||||
global $conf,$db,$langs;
|
||||
|
||||
$errorlevel=error_reporting();
|
||||
error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
|
||||
//error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
|
||||
|
||||
$res=false;
|
||||
|
||||
@@ -721,19 +735,19 @@ class CMailFile
|
||||
if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port');
|
||||
|
||||
// If we use SSL/TLS
|
||||
$server=$conf->global->$keyforsmtpserver;
|
||||
$secure='';
|
||||
$server = $conf->global->$keyforsmtpserver;
|
||||
$secure = '';
|
||||
if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
|
||||
if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
|
||||
|
||||
$this->transport = Swift_SmtpTransport::newInstance($server, $conf->global->$keyforsmtpport, $secure);
|
||||
$this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
|
||||
|
||||
if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
|
||||
if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
|
||||
//$smtps->_msgReplyTo = 'reply@web.com';
|
||||
|
||||
// Create the Mailer using your created Transport
|
||||
$this->mailer = Swift_Mailer::newInstance($this->transport);
|
||||
$this->mailer = new Swift_Mailer($this->transport);
|
||||
|
||||
if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
|
||||
// To use the ArrayLogger
|
||||
@@ -751,7 +765,7 @@ class CMailFile
|
||||
if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
|
||||
|
||||
$res = true;
|
||||
if (! empty($this->error) && ! $result) {
|
||||
if (! empty($this->error) || ! $result) {
|
||||
dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
|
||||
$res=false;
|
||||
} else {
|
||||
|
||||
@@ -460,7 +460,7 @@ class Notify
|
||||
$message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
|
||||
$message.= "\n";
|
||||
$message.= $mesg;
|
||||
if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
|
||||
if ($link) $message.= "\n" . $urlwithroot . $link;
|
||||
|
||||
$parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename);
|
||||
$reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
@@ -555,77 +555,77 @@ class Notify
|
||||
|
||||
switch ($notifcode) {
|
||||
case 'BILL_VALIDATE':
|
||||
$link='/compta/facture/card.php?facid='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'facture';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$link);
|
||||
break;
|
||||
case 'BILL_PAYED':
|
||||
$link='/compta/facture/card.php?facid='.$object->id;
|
||||
$link ='<a href="' . $urlwithroot . '/compta/facture/card.php?facid='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'facture';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$link);
|
||||
break;
|
||||
case 'ORDER_VALIDATE':
|
||||
$link='/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->commande->dir_output;
|
||||
$object_type = 'order';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$link);
|
||||
break;
|
||||
case 'PROPAL_VALIDATE':
|
||||
$link='/comm/propal/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->propal->dir_output;
|
||||
$object_type = 'propal';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$link);
|
||||
break;
|
||||
case 'PROPAL_CLOSE_SIGNED':
|
||||
$link='/comm/propal/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->propal->dir_output;
|
||||
$object_type = 'propal';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned",$link);
|
||||
break;
|
||||
case 'FICHINTER_ADD_CONTACT':
|
||||
$link='/fichinter/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'ficheinter';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$link);
|
||||
break;
|
||||
case 'FICHINTER_VALIDATE':
|
||||
$link='/fichinter/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fichinter/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->facture->dir_output;
|
||||
$object_type = 'ficheinter';
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref);
|
||||
$mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$link);
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_VALIDATE':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_APPROVE':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_APPROVE2':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->commande->dir_output;
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'ORDER_SUPPLIER_REFUSE':
|
||||
$link='/fourn/commande/card.php?id='.$object->id;
|
||||
$link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id='.$object->id . '">' . $newref . '</a>';
|
||||
$dir_output = $conf->fournisseur->dir_output.'/commande/';
|
||||
$object_type = 'order_supplier';
|
||||
$mesg = $langs->transnoentitiesnoconv("Hello").",\n\n";
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs));
|
||||
$mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$link,$user->getFullName($langs));
|
||||
$mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n";
|
||||
break;
|
||||
case 'SHIPPING_VALIDATE':
|
||||
@@ -650,7 +650,7 @@ class Notify
|
||||
$message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n";
|
||||
$message.= "\n";
|
||||
$message.= $mesg;
|
||||
if ($link) $message=dol_concatdesc($message,$urlwithroot.$link);
|
||||
$message = nl2br($message);
|
||||
|
||||
// Replace keyword __SUPERVISOREMAIL__
|
||||
if (preg_match('/__SUPERVISOREMAIL__/', $sendto))
|
||||
@@ -677,7 +677,6 @@ class Notify
|
||||
if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject'];
|
||||
if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message'];
|
||||
}
|
||||
|
||||
$mailfile = new CMailFile(
|
||||
$subject,
|
||||
$sendto,
|
||||
@@ -689,7 +688,7 @@ class Notify
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
-1
|
||||
1
|
||||
);
|
||||
|
||||
if ($mailfile->sendfile())
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Doctrine\Common\Lexer\AbstractLexer;
|
||||
|
||||
class EmailLexer extends AbstractLexer
|
||||
{
|
||||
//ASCII values
|
||||
const C_DEL = 127;
|
||||
const C_NUL = 0;
|
||||
const S_AT = 64;
|
||||
const S_BACKSLASH = 92;
|
||||
const S_DOT = 46;
|
||||
const S_DQUOTE = 34;
|
||||
const S_OPENPARENTHESIS = 49;
|
||||
const S_CLOSEPARENTHESIS = 261;
|
||||
const S_OPENBRACKET = 262;
|
||||
const S_CLOSEBRACKET = 263;
|
||||
const S_HYPHEN = 264;
|
||||
const S_COLON = 265;
|
||||
const S_DOUBLECOLON = 266;
|
||||
const S_SP = 267;
|
||||
const S_HTAB = 268;
|
||||
const S_CR = 269;
|
||||
const S_LF = 270;
|
||||
const S_IPV6TAG = 271;
|
||||
const S_LOWERTHAN = 272;
|
||||
const S_GREATERTHAN = 273;
|
||||
const S_COMMA = 274;
|
||||
const S_SEMICOLON = 275;
|
||||
const S_OPENQBRACKET = 276;
|
||||
const S_CLOSEQBRACKET = 277;
|
||||
const S_SLASH = 278;
|
||||
const S_EMPTY = null;
|
||||
const GENERIC = 300;
|
||||
const CRLF = 301;
|
||||
const INVALID = 302;
|
||||
const ASCII_INVALID_FROM = 127;
|
||||
const ASCII_INVALID_TO = 199;
|
||||
|
||||
/**
|
||||
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $charValue = array(
|
||||
'(' => self::S_OPENPARENTHESIS,
|
||||
')' => self::S_CLOSEPARENTHESIS,
|
||||
'<' => self::S_LOWERTHAN,
|
||||
'>' => self::S_GREATERTHAN,
|
||||
'[' => self::S_OPENBRACKET,
|
||||
']' => self::S_CLOSEBRACKET,
|
||||
':' => self::S_COLON,
|
||||
';' => self::S_SEMICOLON,
|
||||
'@' => self::S_AT,
|
||||
'\\' => self::S_BACKSLASH,
|
||||
'/' => self::S_SLASH,
|
||||
',' => self::S_COMMA,
|
||||
'.' => self::S_DOT,
|
||||
'"' => self::S_DQUOTE,
|
||||
'-' => self::S_HYPHEN,
|
||||
'::' => self::S_DOUBLECOLON,
|
||||
' ' => self::S_SP,
|
||||
"\t" => self::S_HTAB,
|
||||
"\r" => self::S_CR,
|
||||
"\n" => self::S_LF,
|
||||
"\r\n" => self::CRLF,
|
||||
'IPv6' => self::S_IPV6TAG,
|
||||
'{' => self::S_OPENQBRACKET,
|
||||
'}' => self::S_CLOSEQBRACKET,
|
||||
'' => self::S_EMPTY,
|
||||
'\0' => self::C_NUL,
|
||||
);
|
||||
|
||||
protected $hasInvalidTokens = false;
|
||||
|
||||
protected $previous;
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->hasInvalidTokens = false;
|
||||
parent::reset();
|
||||
}
|
||||
|
||||
public function hasInvalidTokens()
|
||||
{
|
||||
return $this->hasInvalidTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @throws \UnexpectedValueException
|
||||
* @return boolean
|
||||
*/
|
||||
public function find($type)
|
||||
{
|
||||
$search = clone $this;
|
||||
$search->skipUntil($type);
|
||||
|
||||
if (!$search->lookahead) {
|
||||
throw new \UnexpectedValueException($type . ' not found');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* getPrevious
|
||||
*
|
||||
* @return array token
|
||||
*/
|
||||
public function getPrevious()
|
||||
{
|
||||
return $this->previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* moveNext
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveNext()
|
||||
{
|
||||
$this->previous = $this->token;
|
||||
|
||||
return parent::moveNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexical catchable patterns.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return array(
|
||||
'[a-zA-Z_]+[46]?', //ASCII and domain literal
|
||||
'[^\x00-\x7F]', //UTF-8
|
||||
'[0-9]+',
|
||||
'\r\n',
|
||||
'::',
|
||||
'\s+?',
|
||||
'.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexical non-catchable patterns.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getNonCatchablePatterns()
|
||||
{
|
||||
return array('[\xA0-\xff]+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve token type. Also processes the token value if necessary.
|
||||
*
|
||||
* @param string $value
|
||||
* @throws \InvalidArgumentException
|
||||
* @return integer
|
||||
*/
|
||||
protected function getType(&$value)
|
||||
{
|
||||
if ($this->isNullType($value)) {
|
||||
return self::C_NUL;
|
||||
}
|
||||
|
||||
if ($this->isValid($value)) {
|
||||
return $this->charValue[$value];
|
||||
}
|
||||
|
||||
if ($this->isUTF8Invalid($value)) {
|
||||
$this->hasInvalidTokens = true;
|
||||
return self::INVALID;
|
||||
}
|
||||
|
||||
return self::GENERIC;
|
||||
}
|
||||
|
||||
protected function isValid($value)
|
||||
{
|
||||
if (isset($this->charValue[$value])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isNullType($value)
|
||||
{
|
||||
if ($value === "\0") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isUTF8Invalid($value)
|
||||
{
|
||||
if (preg_match('/\p{Cc}+/u', $value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function getModifiers()
|
||||
{
|
||||
return 'iu';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\NoLocalPart;
|
||||
use Egulias\EmailValidator\Parser\DomainPart;
|
||||
use Egulias\EmailValidator\Parser\LocalPart;
|
||||
use Egulias\EmailValidator\Warning\EmailTooLong;
|
||||
|
||||
/**
|
||||
* EmailParser
|
||||
*
|
||||
* @author Eduardo Gulias Davis <me@egulias.com>
|
||||
*/
|
||||
class EmailParser
|
||||
{
|
||||
const EMAIL_MAX_LENGTH = 254;
|
||||
|
||||
protected $warnings;
|
||||
protected $domainPart = '';
|
||||
protected $localPart = '';
|
||||
protected $lexer;
|
||||
protected $localPartParser;
|
||||
protected $domainPartParser;
|
||||
|
||||
public function __construct(EmailLexer $lexer)
|
||||
{
|
||||
$this->lexer = $lexer;
|
||||
$this->localPartParser = new LocalPart($this->lexer);
|
||||
$this->domainPartParser = new DomainPart($this->lexer);
|
||||
$this->warnings = new \SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $str
|
||||
* @return array
|
||||
*/
|
||||
public function parse($str)
|
||||
{
|
||||
$this->lexer->setInput($str);
|
||||
|
||||
if (!$this->hasAtToken()) {
|
||||
throw new NoLocalPart();
|
||||
}
|
||||
|
||||
|
||||
$this->localPartParser->parse($str);
|
||||
$this->domainPartParser->parse($str);
|
||||
|
||||
$this->setParts($str);
|
||||
|
||||
if ($this->lexer->hasInvalidTokens()) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
return array('local' => $this->localPart, 'domain' => $this->domainPart);
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
$localPartWarnings = $this->localPartParser->getWarnings();
|
||||
$domainPartWarnings = $this->domainPartParser->getWarnings();
|
||||
$this->warnings = array_merge($localPartWarnings, $domainPartWarnings);
|
||||
|
||||
$this->addLongEmailWarning($this->localPart, $this->domainPart);
|
||||
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
public function getParsedDomainPart()
|
||||
{
|
||||
return $this->domainPart;
|
||||
}
|
||||
|
||||
protected function setParts($email)
|
||||
{
|
||||
$parts = explode('@', $email);
|
||||
$this->domainPart = $this->domainPartParser->getDomainPart();
|
||||
$this->localPart = $parts[0];
|
||||
}
|
||||
|
||||
protected function hasAtToken()
|
||||
{
|
||||
$this->lexer->moveNext();
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_AT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $localPart
|
||||
* @param string $parsedDomainPart
|
||||
*/
|
||||
protected function addLongEmailWarning($localPart, $parsedDomainPart)
|
||||
{
|
||||
if (strlen($localPart . '@' . $parsedDomainPart) > self::EMAIL_MAX_LENGTH) {
|
||||
$this->warnings[EmailTooLong::CODE] = new EmailTooLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
use Egulias\EmailValidator\Validation\EmailValidation;
|
||||
|
||||
class EmailValidator
|
||||
{
|
||||
/**
|
||||
* @var EmailLexer
|
||||
*/
|
||||
private $lexer;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $warnings;
|
||||
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->lexer = new EmailLexer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
* @param EmailValidation $emailValidation
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($email, EmailValidation $emailValidation)
|
||||
{
|
||||
$isValid = $emailValidation->isValid($email, $this->lexer);
|
||||
$this->warnings = $emailValidation->getWarnings();
|
||||
$this->error = $emailValidation->getError();
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasWarnings()
|
||||
{
|
||||
return !empty($this->warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return InvalidEmail
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class AtextAfterCFWS extends InvalidEmail
|
||||
{
|
||||
const CODE = 133;
|
||||
const REASON = "ATEXT found after CFWS";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CRLFAtTheEnd extends InvalidEmail
|
||||
{
|
||||
const CODE = 149;
|
||||
const REASON = "CRLF at the end";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CRLFX2 extends InvalidEmail
|
||||
{
|
||||
const CODE = 148;
|
||||
const REASON = "Folding whitespace CR LF found twice";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CRNoLF extends InvalidEmail
|
||||
{
|
||||
const CODE = 150;
|
||||
const REASON = "Missing LF after CR";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CharNotAllowed extends InvalidEmail
|
||||
{
|
||||
const CODE = 201;
|
||||
const REASON = "Non allowed character in domain";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class CommaInDomain extends InvalidEmail
|
||||
{
|
||||
const CODE = 200;
|
||||
const REASON = "Comma ',' is not allowed in domain part";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ConsecutiveAt extends InvalidEmail
|
||||
{
|
||||
const CODE = 128;
|
||||
const REASON = "Consecutive AT";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ConsecutiveDot extends InvalidEmail
|
||||
{
|
||||
const CODE = 132;
|
||||
const REASON = "Consecutive DOT";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class DomainHyphened extends InvalidEmail
|
||||
{
|
||||
const CODE = 144;
|
||||
const REASON = "Hyphen found in domain";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class DotAtEnd extends InvalidEmail
|
||||
{
|
||||
const CODE = 142;
|
||||
const REASON = "Dot at the end";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class DotAtStart extends InvalidEmail
|
||||
{
|
||||
const CODE = 141;
|
||||
const REASON = "Found DOT at start";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingAT extends InvalidEmail
|
||||
{
|
||||
const CODE = 202;
|
||||
const REASON = "Expecting AT '@' ";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingATEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 137;
|
||||
const REASON = "Expecting ATEXT";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingCTEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 139;
|
||||
const REASON = "Expecting CTEXT";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingDTEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 129;
|
||||
const REASON = "Expected DTEXT";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectingDomainLiteralClose extends InvalidEmail
|
||||
{
|
||||
const CODE = 137;
|
||||
const REASON = "Closing bracket ']' for domain literal not found";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class ExpectedQPair extends InvalidEmail
|
||||
{
|
||||
const CODE = 136;
|
||||
const REASON = "Expecting QPAIR";
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
abstract class InvalidEmail extends \InvalidArgumentException
|
||||
{
|
||||
const REASON = "Invalid email";
|
||||
const CODE = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(static::REASON, static::CODE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class NoDNSRecord extends InvalidEmail
|
||||
{
|
||||
const CODE = 5;
|
||||
const REASON = 'No MX or A DSN record was found for this email';
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class NoDomainPart extends InvalidEmail
|
||||
{
|
||||
const CODE = 131;
|
||||
const REASON = "No Domain part";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class NoLocalPart extends InvalidEmail
|
||||
{
|
||||
const CODE = 130;
|
||||
const REASON = "No local part";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class UnclosedComment extends InvalidEmail
|
||||
{
|
||||
const CODE = 146;
|
||||
const REASON = "No colosing comment token found";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class UnclosedQuotedString extends InvalidEmail
|
||||
{
|
||||
const CODE = 145;
|
||||
const REASON = "Unclosed quoted string";
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
class UnopenedComment extends InvalidEmail
|
||||
{
|
||||
const CODE = 152;
|
||||
const REASON = "No opening comment token found";
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\CharNotAllowed;
|
||||
use Egulias\EmailValidator\Exception\CommaInDomain;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Exception\CRLFAtTheEnd;
|
||||
use Egulias\EmailValidator\Exception\CRNoLF;
|
||||
use Egulias\EmailValidator\Exception\DomainHyphened;
|
||||
use Egulias\EmailValidator\Exception\DotAtEnd;
|
||||
use Egulias\EmailValidator\Exception\DotAtStart;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDomainLiteralClose;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDTEXT;
|
||||
use Egulias\EmailValidator\Exception\NoDomainPart;
|
||||
use Egulias\EmailValidator\Exception\UnopenedComment;
|
||||
use Egulias\EmailValidator\Warning\AddressLiteral;
|
||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
||||
use Egulias\EmailValidator\Warning\DeprecatedComment;
|
||||
use Egulias\EmailValidator\Warning\DomainLiteral;
|
||||
use Egulias\EmailValidator\Warning\DomainTooLong;
|
||||
use Egulias\EmailValidator\Warning\IPV6BadChar;
|
||||
use Egulias\EmailValidator\Warning\IPV6ColonEnd;
|
||||
use Egulias\EmailValidator\Warning\IPV6ColonStart;
|
||||
use Egulias\EmailValidator\Warning\IPV6Deprecated;
|
||||
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
|
||||
use Egulias\EmailValidator\Warning\IPV6GroupCount;
|
||||
use Egulias\EmailValidator\Warning\IPV6MaxGroups;
|
||||
use Egulias\EmailValidator\Warning\LabelTooLong;
|
||||
use Egulias\EmailValidator\Warning\ObsoleteDTEXT;
|
||||
use Egulias\EmailValidator\Warning\TLD;
|
||||
|
||||
class DomainPart extends Parser
|
||||
{
|
||||
const DOMAIN_MAX_LENGTH = 254;
|
||||
protected $domainPart = '';
|
||||
|
||||
public function parse($domainPart)
|
||||
{
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
|
||||
throw new DotAtStart();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) {
|
||||
throw new NoDomainPart();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
|
||||
throw new DomainHyphened();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
|
||||
$this->parseDomainComments();
|
||||
}
|
||||
|
||||
$domain = $this->doParseDomainPart();
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
$length = strlen($domain);
|
||||
|
||||
if ($prev['type'] === EmailLexer::S_DOT) {
|
||||
throw new DotAtEnd();
|
||||
}
|
||||
if ($prev['type'] === EmailLexer::S_HYPHEN) {
|
||||
throw new DomainHyphened();
|
||||
}
|
||||
if ($length > self::DOMAIN_MAX_LENGTH) {
|
||||
$this->warnings[DomainTooLong::CODE] = new DomainTooLong();
|
||||
}
|
||||
if ($prev['type'] === EmailLexer::S_CR) {
|
||||
throw new CRLFAtTheEnd();
|
||||
}
|
||||
$this->domainPart = $domain;
|
||||
}
|
||||
|
||||
public function getDomainPart()
|
||||
{
|
||||
return $this->domainPart;
|
||||
}
|
||||
|
||||
public function checkIPV6Tag($addressLiteral, $maxGroups = 8)
|
||||
{
|
||||
$prev = $this->lexer->getPrevious();
|
||||
if ($prev['type'] === EmailLexer::S_COLON) {
|
||||
$this->warnings[IPV6ColonEnd::CODE] = new IPV6ColonEnd();
|
||||
}
|
||||
|
||||
$IPv6 = substr($addressLiteral, 5);
|
||||
//Daniel Marschall's new IPv6 testing strategy
|
||||
$matchesIP = explode(':', $IPv6);
|
||||
$groupCount = count($matchesIP);
|
||||
$colons = strpos($IPv6, '::');
|
||||
|
||||
if (count(preg_grep('/^[0-9A-Fa-f]{0,4}$/', $matchesIP, PREG_GREP_INVERT)) !== 0) {
|
||||
$this->warnings[IPV6BadChar::CODE] = new IPV6BadChar();
|
||||
}
|
||||
|
||||
if ($colons === false) {
|
||||
// We need exactly the right number of groups
|
||||
if ($groupCount !== $maxGroups) {
|
||||
$this->warnings[IPV6GroupCount::CODE] = new IPV6GroupCount();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($colons !== strrpos($IPv6, '::')) {
|
||||
$this->warnings[IPV6DoubleColon::CODE] = new IPV6DoubleColon();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($colons === 0 || $colons === (strlen($IPv6) - 2)) {
|
||||
// RFC 4291 allows :: at the start or end of an address
|
||||
//with 7 other groups in addition
|
||||
++$maxGroups;
|
||||
}
|
||||
|
||||
if ($groupCount > $maxGroups) {
|
||||
$this->warnings[IPV6MaxGroups::CODE] = new IPV6MaxGroups();
|
||||
} elseif ($groupCount === $maxGroups) {
|
||||
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
|
||||
}
|
||||
}
|
||||
|
||||
protected function doParseDomainPart()
|
||||
{
|
||||
$domain = '';
|
||||
$openedParenthesis = 0;
|
||||
do {
|
||||
$prev = $this->lexer->getPrevious();
|
||||
|
||||
$this->checkNotAllowedChars($this->lexer->token);
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->parseComments();
|
||||
$openedParenthesis += $this->getOpenedParenthesis();
|
||||
$this->lexer->moveNext();
|
||||
$tmpPrev = $this->lexer->getPrevious();
|
||||
if ($tmpPrev['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
if ($openedParenthesis === 0) {
|
||||
throw new UnopenedComment();
|
||||
} else {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
$this->checkDomainPartExceptions($prev);
|
||||
|
||||
if ($this->hasBrackets()) {
|
||||
$this->parseDomainLiteral();
|
||||
}
|
||||
|
||||
$this->checkLabelLength($prev);
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$this->parseFWS();
|
||||
}
|
||||
|
||||
$domain .= $this->lexer->token['value'];
|
||||
$this->lexer->moveNext();
|
||||
} while ($this->lexer->token);
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
private function checkNotAllowedChars($token)
|
||||
{
|
||||
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
|
||||
if (isset($notAllowed[$token['type']])) {
|
||||
throw new CharNotAllowed();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDomainLiteral()
|
||||
{
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
|
||||
$this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
|
||||
}
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_IPV6TAG)) {
|
||||
$lexer = clone $this->lexer;
|
||||
$lexer->moveNext();
|
||||
if ($lexer->isNextToken(EmailLexer::S_DOUBLECOLON)) {
|
||||
$this->warnings[IPV6ColonStart::CODE] = new IPV6ColonStart();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->doParseDomainLiteral();
|
||||
}
|
||||
|
||||
protected function doParseDomainLiteral()
|
||||
{
|
||||
$IPv6TAG = false;
|
||||
$addressLiteral = '';
|
||||
do {
|
||||
if ($this->lexer->token['type'] === EmailLexer::C_NUL) {
|
||||
throw new ExpectingDTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::INVALID ||
|
||||
$this->lexer->token['type'] === EmailLexer::C_DEL ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_LF
|
||||
) {
|
||||
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENQBRACKET, EmailLexer::S_OPENBRACKET))) {
|
||||
throw new ExpectingDTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextTokenAny(
|
||||
array(EmailLexer::S_HTAB, EmailLexer::S_SP, $this->lexer->token['type'] === EmailLexer::CRLF)
|
||||
)) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
$this->parseFWS();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
||||
throw new CRNoLF();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
|
||||
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
|
||||
$addressLiteral .= $this->lexer->token['value'];
|
||||
$this->lexer->moveNext();
|
||||
$this->validateQuotedPair();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) {
|
||||
$IPv6TAG = true;
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEQBRACKET) {
|
||||
break;
|
||||
}
|
||||
|
||||
$addressLiteral .= $this->lexer->token['value'];
|
||||
|
||||
} while ($this->lexer->moveNext());
|
||||
|
||||
$addressLiteral = str_replace('[', '', $addressLiteral);
|
||||
$addressLiteral = $this->checkIPV4Tag($addressLiteral);
|
||||
|
||||
if (false === $addressLiteral) {
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
if (!$IPv6TAG) {
|
||||
$this->warnings[DomainLiteral::CODE] = new DomainLiteral();
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
$this->warnings[AddressLiteral::CODE] = new AddressLiteral();
|
||||
|
||||
$this->checkIPV6Tag($addressLiteral);
|
||||
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
protected function checkIPV4Tag($addressLiteral)
|
||||
{
|
||||
$matchesIP = array();
|
||||
|
||||
// Extract IPv4 part from the end of the address-literal (if there is one)
|
||||
if (preg_match(
|
||||
'/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/',
|
||||
$addressLiteral,
|
||||
$matchesIP
|
||||
) > 0
|
||||
) {
|
||||
$index = strrpos($addressLiteral, $matchesIP[0]);
|
||||
if ($index === 0) {
|
||||
$this->warnings[AddressLiteral::CODE] = new AddressLiteral();
|
||||
return false;
|
||||
}
|
||||
// Convert IPv4 part to IPv6 format for further testing
|
||||
$addressLiteral = substr($addressLiteral, 0, $index) . '0:0';
|
||||
}
|
||||
|
||||
return $addressLiteral;
|
||||
}
|
||||
|
||||
protected function checkDomainPartExceptions($prev)
|
||||
{
|
||||
$invalidDomainTokens = array(
|
||||
EmailLexer::S_DQUOTE => true,
|
||||
EmailLexer::S_SEMICOLON => true,
|
||||
EmailLexer::S_GREATERTHAN => true,
|
||||
EmailLexer::S_LOWERTHAN => true,
|
||||
);
|
||||
|
||||
if (isset($invalidDomainTokens[$this->lexer->token['type']])) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_COMMA) {
|
||||
throw new CommaInDomain();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_AT) {
|
||||
throw new ConsecutiveAt();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENQBRACKET && $prev['type'] !== EmailLexer::S_AT) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
throw new DomainHyphened();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH
|
||||
&& $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasBrackets()
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_CLOSEBRACKET);
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new ExpectingDomainLiteralClose();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function checkLabelLength($prev)
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
$prev['type'] === EmailLexer::GENERIC &&
|
||||
strlen($prev['value']) > 63
|
||||
) {
|
||||
$this->warnings[LabelTooLong::CODE] = new LabelTooLong();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDomainComments()
|
||||
{
|
||||
$this->isUnclosedComment();
|
||||
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
$this->warnEscaping();
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
|
||||
protected function addTLDWarnings()
|
||||
{
|
||||
if ($this->warnings[DomainLiteral::CODE]) {
|
||||
$this->warnings[TLD::CODE] = new TLD();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\Exception\DotAtEnd;
|
||||
use Egulias\EmailValidator\Exception\DotAtStart;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Exception\ExpectingAT;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\UnclosedQuotedString;
|
||||
use Egulias\EmailValidator\Exception\UnopenedComment;
|
||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
||||
use Egulias\EmailValidator\Warning\LocalTooLong;
|
||||
|
||||
class LocalPart extends Parser
|
||||
{
|
||||
public function parse($localPart)
|
||||
{
|
||||
$parseDQuote = true;
|
||||
$closingQuote = false;
|
||||
$openedParenthesis = 0;
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
|
||||
throw new DotAtStart();
|
||||
}
|
||||
|
||||
$closingQuote = $this->checkDQUOTE($closingQuote);
|
||||
if ($closingQuote && $parseDQuote) {
|
||||
$parseDQuote = $this->parseDoubleQuote();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
|
||||
$this->parseComments();
|
||||
$openedParenthesis += $this->getOpenedParenthesis();
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
|
||||
if ($openedParenthesis === 0) {
|
||||
throw new UnopenedComment();
|
||||
} else {
|
||||
$openedParenthesis--;
|
||||
}
|
||||
}
|
||||
|
||||
$this->checkConsecutiveDots();
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||
) {
|
||||
throw new DotAtEnd();
|
||||
}
|
||||
|
||||
$this->warnEscaping();
|
||||
$this->isInvalidToken($this->lexer->token, $closingQuote);
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$this->parseFWS();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
if (strlen($prev['value']) > LocalTooLong::LOCAL_PART_LENGTH) {
|
||||
$this->warnings[LocalTooLong::CODE] = new LocalTooLong();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseDoubleQuote()
|
||||
{
|
||||
$parseAgain = true;
|
||||
$special = array(
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_HTAB => true,
|
||||
EmailLexer::S_LF => true
|
||||
);
|
||||
|
||||
$invalid = array(
|
||||
EmailLexer::C_NUL => true,
|
||||
EmailLexer::S_HTAB => true,
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_LF => true
|
||||
);
|
||||
$setSpecialsWarning = true;
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
|
||||
$parseAgain = false;
|
||||
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
$setSpecialsWarning = false;
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
|
||||
$prev = $this->lexer->getPrevious();
|
||||
|
||||
if ($prev['type'] === EmailLexer::S_BACKSLASH) {
|
||||
if (!$this->checkDQUOTE(false)) {
|
||||
throw new UnclosedQuotedString();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
throw new ExpectingAT();
|
||||
}
|
||||
|
||||
return $parseAgain;
|
||||
}
|
||||
|
||||
protected function isInvalidToken($token, $closingQuote)
|
||||
{
|
||||
$forbidden = array(
|
||||
EmailLexer::S_COMMA,
|
||||
EmailLexer::S_CLOSEBRACKET,
|
||||
EmailLexer::S_OPENBRACKET,
|
||||
EmailLexer::S_GREATERTHAN,
|
||||
EmailLexer::S_LOWERTHAN,
|
||||
EmailLexer::S_COLON,
|
||||
EmailLexer::S_SEMICOLON,
|
||||
EmailLexer::INVALID
|
||||
);
|
||||
|
||||
if (in_array($token['type'], $forbidden) && !$closingQuote) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\AtextAfterCFWS;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Exception\CRLFAtTheEnd;
|
||||
use Egulias\EmailValidator\Exception\CRLFX2;
|
||||
use Egulias\EmailValidator\Exception\CRNoLF;
|
||||
use Egulias\EmailValidator\Exception\ExpectedQPair;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\ExpectingCTEXT;
|
||||
use Egulias\EmailValidator\Exception\UnclosedComment;
|
||||
use Egulias\EmailValidator\Exception\UnclosedQuotedString;
|
||||
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
||||
use Egulias\EmailValidator\Warning\Comment;
|
||||
use Egulias\EmailValidator\Warning\QuotedPart;
|
||||
use Egulias\EmailValidator\Warning\QuotedString;
|
||||
|
||||
abstract class Parser
|
||||
{
|
||||
protected $warnings = [];
|
||||
protected $lexer;
|
||||
protected $openedParenthesis = 0;
|
||||
|
||||
public function __construct(EmailLexer $lexer)
|
||||
{
|
||||
$this->lexer = $lexer;
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
abstract public function parse($str);
|
||||
|
||||
/** @return int */
|
||||
public function getOpenedParenthesis()
|
||||
{
|
||||
return $this->openedParenthesis;
|
||||
}
|
||||
|
||||
/**
|
||||
* validateQuotedPair
|
||||
*/
|
||||
protected function validateQuotedPair()
|
||||
{
|
||||
if (!($this->lexer->token['type'] === EmailLexer::INVALID
|
||||
|| $this->lexer->token['type'] === EmailLexer::C_DEL)) {
|
||||
throw new ExpectedQPair();
|
||||
}
|
||||
|
||||
$this->warnings[QuotedPart::CODE] =
|
||||
new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']);
|
||||
}
|
||||
|
||||
protected function parseComments()
|
||||
{
|
||||
$this->openedParenthesis = 1;
|
||||
$this->isUnclosedComment();
|
||||
$this->warnings[Comment::CODE] = new Comment();
|
||||
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
$this->openedParenthesis++;
|
||||
}
|
||||
$this->warnEscaping();
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->isNextTokenAny(array(EmailLexer::GENERIC, EmailLexer::S_EMPTY))) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_AT)) {
|
||||
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
|
||||
}
|
||||
}
|
||||
|
||||
protected function isUnclosedComment()
|
||||
{
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);
|
||||
return true;
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new UnclosedComment();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseFWS()
|
||||
{
|
||||
$previous = $this->lexer->getPrevious();
|
||||
|
||||
$this->checkCRLFInFWS();
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CR) {
|
||||
throw new CRNoLF();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
|
||||
throw new AtextAfterCFWS();
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
|
||||
throw new ExpectingCTEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) {
|
||||
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
|
||||
} else {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkConsecutiveDots()
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
throw new ConsecutiveDot();
|
||||
}
|
||||
}
|
||||
|
||||
protected function isFWS()
|
||||
{
|
||||
if ($this->escaped()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_SP ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_HTAB ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_CR ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_LF ||
|
||||
$this->lexer->token['type'] === EmailLexer::CRLF
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function escaped()
|
||||
{
|
||||
$previous = $this->lexer->getPrevious();
|
||||
|
||||
if ($previous['type'] === EmailLexer::S_BACKSLASH
|
||||
&&
|
||||
$this->lexer->token['type'] !== EmailLexer::GENERIC
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function warnEscaping()
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->warnings[QuotedPart::CODE] =
|
||||
new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
protected function checkDQUOTE($hasClosingQuote)
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE) {
|
||||
return $hasClosingQuote;
|
||||
}
|
||||
if ($hasClosingQuote) {
|
||||
return $hasClosingQuote;
|
||||
}
|
||||
$previous = $this->lexer->getPrevious();
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_DQUOTE);
|
||||
$hasClosingQuote = true;
|
||||
} catch (\Exception $e) {
|
||||
throw new UnclosedQuotedString();
|
||||
}
|
||||
$this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], $this->lexer->token['value']);
|
||||
|
||||
return $hasClosingQuote;
|
||||
}
|
||||
|
||||
protected function checkCRLFInFWS()
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::CRLF) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
throw new CRLFX2();
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
throw new CRLFAtTheEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
|
||||
use Egulias\EmailValidator\Exception\NoDNSRecord;
|
||||
|
||||
class DNSCheckValidation implements EmailValidation
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $warnings = [];
|
||||
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
// use the input to check DNS if we cannot extract something similar to a domain
|
||||
$host = $email;
|
||||
|
||||
// Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
|
||||
if (false !== $lastAtPos = strrpos($email, '@')) {
|
||||
$host = substr($email, $lastAtPos + 1);
|
||||
}
|
||||
|
||||
return $this->checkDNS($host);
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
|
||||
protected function checkDNS($host)
|
||||
{
|
||||
$host = rtrim($host, '.') . '.';
|
||||
|
||||
$Aresult = true;
|
||||
$MXresult = checkdnsrr($host, 'MX');
|
||||
|
||||
if (!$MXresult) {
|
||||
$this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord();
|
||||
$Aresult = checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA');
|
||||
if (!$Aresult) {
|
||||
$this->error = new NoDNSRecord();
|
||||
}
|
||||
}
|
||||
return $MXresult || $Aresult;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
use Egulias\EmailValidator\Warning\Warning;
|
||||
|
||||
interface EmailValidation
|
||||
{
|
||||
/**
|
||||
* Returns true if the given email is valid.
|
||||
*
|
||||
* @param string $email The email you want to validate.
|
||||
* @param EmailLexer $emailLexer The email lexer.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($email, EmailLexer $emailLexer);
|
||||
|
||||
/**
|
||||
* Returns the validation error.
|
||||
*
|
||||
* @return InvalidEmail|null
|
||||
*/
|
||||
public function getError();
|
||||
|
||||
/**
|
||||
* Returns the validation warnings.
|
||||
*
|
||||
* @return Warning[]
|
||||
*/
|
||||
public function getWarnings();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation\Error;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class RFCWarnings extends InvalidEmail
|
||||
{
|
||||
const CODE = 997;
|
||||
const REASON = 'Warnings were found.';
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation\Error;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class SpoofEmail extends InvalidEmail
|
||||
{
|
||||
const CODE = 998;
|
||||
const REASON = "The email contains mixed UTF8 chars that makes it suspicious";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class EmptyValidationList extends \InvalidArgumentException
|
||||
{
|
||||
public function __construct($code = 0, Exception $previous = null)
|
||||
{
|
||||
parent::__construct("Empty validation list is not allowed", $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class MultipleErrors extends InvalidEmail
|
||||
{
|
||||
const CODE = 999;
|
||||
const REASON = "Accumulated errors for multiple validations";
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $errors = [];
|
||||
|
||||
public function __construct(array $errors)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Validation\Exception\EmptyValidationList;
|
||||
|
||||
class MultipleValidationWithAnd implements EmailValidation
|
||||
{
|
||||
/**
|
||||
* If one of validations gets failure skips all succeeding validation.
|
||||
* This means MultipleErrors will only contain a single error which first found.
|
||||
*/
|
||||
const STOP_ON_ERROR = 0;
|
||||
|
||||
/**
|
||||
* All of validations will be invoked even if one of them got failure.
|
||||
* So MultipleErrors will contain all causes.
|
||||
*/
|
||||
const ALLOW_ALL_ERRORS = 1;
|
||||
|
||||
/**
|
||||
* @var EmailValidation[]
|
||||
*/
|
||||
private $validations = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $warnings = [];
|
||||
|
||||
/**
|
||||
* @var MultipleErrors
|
||||
*/
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* @param EmailValidation[] $validations The validations.
|
||||
* @param int $mode The validation mode (one of the constants).
|
||||
*/
|
||||
public function __construct(array $validations, $mode = self::ALLOW_ALL_ERRORS)
|
||||
{
|
||||
if (count($validations) == 0) {
|
||||
throw new EmptyValidationList();
|
||||
}
|
||||
|
||||
$this->validations = $validations;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
$result = true;
|
||||
$errors = [];
|
||||
foreach ($this->validations as $validation) {
|
||||
$emailLexer->reset();
|
||||
$result = $result && $validation->isValid($email, $emailLexer);
|
||||
$this->warnings = array_merge($this->warnings, $validation->getWarnings());
|
||||
$errors = $this->addNewError($validation->getError(), $errors);
|
||||
|
||||
if ($this->shouldStop($result)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
$this->error = new MultipleErrors($errors);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function addNewError($possibleError, array $errors)
|
||||
{
|
||||
if (null !== $possibleError) {
|
||||
$errors[] = $possibleError;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
private function shouldStop($result)
|
||||
{
|
||||
return !$result && $this->mode === self::STOP_ON_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
use Egulias\EmailValidator\Validation\Error\RFCWarnings;
|
||||
|
||||
class NoRFCWarningsValidation extends RFCValidation
|
||||
{
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
if (!parent::isValid($email, $emailLexer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($this->getWarnings())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->error = new RFCWarnings();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error ?: parent::getError();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\EmailParser;
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
|
||||
class RFCValidation implements EmailValidation
|
||||
{
|
||||
/**
|
||||
* @var EmailParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $warnings = [];
|
||||
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
$this->parser = new EmailParser($emailLexer);
|
||||
try {
|
||||
$this->parser->parse((string)$email);
|
||||
} catch (InvalidEmail $invalid) {
|
||||
$this->error = $invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->warnings = $this->parser->getWarnings();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
return $this->warnings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Validation;
|
||||
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\InvalidEmail;
|
||||
use Egulias\EmailValidator\Validation\Error\SpoofEmail;
|
||||
use \Spoofchecker;
|
||||
|
||||
class SpoofCheckValidation implements EmailValidation
|
||||
{
|
||||
/**
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (!class_exists(Spoofchecker::class)) {
|
||||
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
||||
}
|
||||
}
|
||||
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
$checker = new Spoofchecker();
|
||||
$checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
|
||||
|
||||
if ($checker->isSuspicious($email)) {
|
||||
$this->error = new SpoofEmail();
|
||||
}
|
||||
|
||||
return $this->error === null;
|
||||
}
|
||||
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function getWarnings()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class AddressLiteral extends Warning
|
||||
{
|
||||
const CODE = 12;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Address literal in domain part';
|
||||
$this->rfcNumber = 5321;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class CFWSNearAt extends Warning
|
||||
{
|
||||
const CODE = 49;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = "Deprecated folding white space near @";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class CFWSWithFWS extends Warning
|
||||
{
|
||||
const CODE = 18;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Folding whites space followed by folding white space';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class Comment extends Warning
|
||||
{
|
||||
const CODE = 17;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = "Comments found in this email";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class DeprecatedComment extends Warning
|
||||
{
|
||||
const CODE = 37;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Deprecated comments';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class DomainLiteral extends Warning
|
||||
{
|
||||
const CODE = 70;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Domain Literal';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class DomainTooLong extends Warning
|
||||
{
|
||||
const CODE = 255;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Domain is too long, exceeds 255 chars';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
use Egulias\EmailValidator\EmailParser;
|
||||
|
||||
class EmailTooLong extends Warning
|
||||
{
|
||||
const CODE = 66;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Email is too long, exceeds ' . EmailParser::EMAIL_MAX_LENGTH;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6BadChar extends Warning
|
||||
{
|
||||
const CODE = 74;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Bad char in IPV6 domain literal';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6ColonEnd extends Warning
|
||||
{
|
||||
const CODE = 77;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = ':: found at the end of the domain literal';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6ColonStart extends Warning
|
||||
{
|
||||
const CODE = 76;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = ':: found at the start of the domain literal';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6Deprecated extends Warning
|
||||
{
|
||||
const CODE = 13;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Deprecated form of IPV6';
|
||||
$this->rfcNumber = 5321;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6DoubleColon extends Warning
|
||||
{
|
||||
const CODE = 73;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Double colon found after IPV6 tag';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6GroupCount extends Warning
|
||||
{
|
||||
const CODE = 72;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Group count is not IPV6 valid';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class IPV6MaxGroups extends Warning
|
||||
{
|
||||
const CODE = 75;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Reached the maximum number of IPV6 groups allowed';
|
||||
$this->rfcNumber = 5321;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class LabelTooLong extends Warning
|
||||
{
|
||||
const CODE = 63;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Label too long';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class LocalTooLong extends Warning
|
||||
{
|
||||
const CODE = 64;
|
||||
const LOCAL_PART_LENGTH = 64;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'Local part is too long, exceeds 64 chars (octets)';
|
||||
$this->rfcNumber = 5322;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class NoDNSMXRecord extends Warning
|
||||
{
|
||||
const CODE = 6;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = 'No MX DSN record was found for this email';
|
||||
$this->rfcNumber = 5321;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class ObsoleteDTEXT extends Warning
|
||||
{
|
||||
const CODE = 71;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->rfcNumber = 5322;
|
||||
$this->message = 'Obsolete DTEXT in domain literal';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class QuotedPart extends Warning
|
||||
{
|
||||
const CODE = 36;
|
||||
|
||||
public function __construct($prevToken, $postToken)
|
||||
{
|
||||
$this->message = "Deprecated Quoted String found between $prevToken and $postToken";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class QuotedString extends Warning
|
||||
{
|
||||
const CODE = 11;
|
||||
|
||||
public function __construct($prevToken, $postToken)
|
||||
{
|
||||
$this->message = "Quoted String found between $prevToken and $postToken";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
class TLD extends Warning
|
||||
{
|
||||
const CODE = 9;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->message = "RFC5321, TLD";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Warning;
|
||||
|
||||
abstract class Warning
|
||||
{
|
||||
const CODE = 0;
|
||||
protected $message;
|
||||
protected $rfcNumber;
|
||||
|
||||
public function message()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function code()
|
||||
{
|
||||
return self::CODE;
|
||||
}
|
||||
|
||||
public function RFCNumber()
|
||||
{
|
||||
return $this->rfcNumber;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->message() . " rfc: " . $this->rfcNumber . "interal code: " . static::CODE;
|
||||
}
|
||||
}
|
||||
19
htdocs/includes/egulias/email-validator/LICENSE
Normal file
19
htdocs/includes/egulias/email-validator/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013-2016 Eduardo Gulias Davis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
79
htdocs/includes/egulias/email-validator/README.md
Normal file
79
htdocs/includes/egulias/email-validator/README.md
Normal file
@@ -0,0 +1,79 @@
|
||||
# EmailValidator
|
||||
[](https://travis-ci.org/egulias/EmailValidator) [](https://coveralls.io/r/egulias/EmailValidator?branch=master) [](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
|
||||
=============================
|
||||
With the help of [PHPStorm](https://www.jetbrains.com/phpstorm/)
|
||||
|
||||
## Requirements ##
|
||||
|
||||
* [Composer](https://getcomposer.org) is required for installation
|
||||
* [Spoofchecking](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php) validation requires that your PHP system have the [PHP Internationalization Libraries](http://php.net/manual/en/book.intl.php) (also known as PHP Intl)
|
||||
|
||||
## Installation ##
|
||||
|
||||
Run the command below to install via Composer
|
||||
|
||||
```shell
|
||||
composer require egulias/email-validator "~2.1"
|
||||
```
|
||||
|
||||
## Getting Started ##
|
||||
`EmailValidator`requires you to decide which (or combination of them) validation/s strategy/ies you'd like to follow for each [validation](#available-validations).
|
||||
|
||||
A basic example with the RFC validation
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
$validator = new EmailValidator();
|
||||
$validator->isValid("example@example.com", new RFCValidation()); //true
|
||||
```
|
||||
|
||||
|
||||
### Available validations ###
|
||||
|
||||
1. [RFCValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/RFCValidation.php)
|
||||
2. [NoRFCWarningsValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/NoRFCWarningsValidation.php)
|
||||
3. [DNSCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/DNSCheckValidation.php)
|
||||
4. [SpoofCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php)
|
||||
5. [MultipleValidationWithAnd](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/MultipleValidationWithAnd.php)
|
||||
6. [Your own validation](#how-to-extend)
|
||||
|
||||
`MultipleValidationWithAnd`
|
||||
|
||||
It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\DNSCheckValidation;
|
||||
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
$validator = new EmailValidator();
|
||||
$multipleValidations = new MultipleValidationWithAnd([
|
||||
new RFCValidation(),
|
||||
new DNSCheckValidation()
|
||||
]);
|
||||
$validator->isValid("example@example.com", $multipleValidations); //true
|
||||
```
|
||||
|
||||
### How to extend ###
|
||||
|
||||
It's easy! You just need to extend [EmailValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/EmailValidation.php) and you can use your own validation.
|
||||
|
||||
|
||||
## Other Contributors ##
|
||||
(You can find current contributors [here](https://github.com/egulias/EmailValidator/graphs/contributors))
|
||||
|
||||
As this is a port from another library and work, here are other people related to the previous one:
|
||||
|
||||
* Ricard Clau [@ricardclau](http://github.com/ricardclau): Performance against PHP built-in filter_var
|
||||
* Josepf Bielawski [@stloyd](http://github.com/stloyd): For its first re-work of Dominic's lib
|
||||
* Dominic Sayers [@dominicsayers](http://github.com/dominicsayers): The original isemail function
|
||||
|
||||
## License ##
|
||||
Released under the MIT License attached with this code.
|
||||
|
||||
19
htdocs/includes/lexer/LICENSE
Normal file
19
htdocs/includes/lexer/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2006-2013 Doctrine Project
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
5
htdocs/includes/lexer/README.md
Normal file
5
htdocs/includes/lexer/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Doctrine Lexer
|
||||
|
||||
Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
|
||||
|
||||
This lexer is used in Doctrine Annotations and in Doctrine ORM (DQL).
|
||||
24
htdocs/includes/lexer/composer.json
Normal file
24
htdocs/includes/lexer/composer.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "doctrine/lexer",
|
||||
"type": "library",
|
||||
"description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.",
|
||||
"keywords": ["lexer", "parser"],
|
||||
"homepage": "http://www.doctrine-project.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"},
|
||||
{"name": "Roman Borschel", "email": "roman@code-factory.org"},
|
||||
{"name": "Johannes Schmitt", "email": "schmittjoh@gmail.com"}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Doctrine\\Common\\Lexer\\": "lib/" }
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\Lexer;
|
||||
|
||||
/**
|
||||
* Base class for writing simple lexers, i.e. for creating small DSLs.
|
||||
*
|
||||
* @since 2.0
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
abstract class AbstractLexer
|
||||
{
|
||||
/**
|
||||
* Lexer original input string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $input;
|
||||
|
||||
/**
|
||||
* Array of scanned tokens.
|
||||
*
|
||||
* Each token is an associative array containing three items:
|
||||
* - 'value' : the string value of the token in the input string
|
||||
* - 'type' : the type of the token (identifier, numeric, string, input
|
||||
* parameter, none)
|
||||
* - 'position' : the position of the token in the input string
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $tokens = array();
|
||||
|
||||
/**
|
||||
* Current lexer position in input string.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $position = 0;
|
||||
|
||||
/**
|
||||
* Current peek of current lexer position.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $peek = 0;
|
||||
|
||||
/**
|
||||
* The next token in the input.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $lookahead;
|
||||
|
||||
/**
|
||||
* The last matched/seen token.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* Sets the input data to be tokenized.
|
||||
*
|
||||
* The Lexer is immediately reset and the new input tokenized.
|
||||
* Any unprocessed tokens from any previous input are lost.
|
||||
*
|
||||
* @param string $input The input to be tokenized.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setInput($input)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->tokens = array();
|
||||
|
||||
$this->reset();
|
||||
$this->scan($input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the lexer.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->lookahead = null;
|
||||
$this->token = null;
|
||||
$this->peek = 0;
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the peek pointer to 0.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetPeek()
|
||||
{
|
||||
$this->peek = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the lexer position on the input to the given position.
|
||||
*
|
||||
* @param integer $position Position to place the lexical scanner.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetPosition($position = 0)
|
||||
{
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the original lexer's input until a given position.
|
||||
*
|
||||
* @param integer $position
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputUntilPosition($position)
|
||||
{
|
||||
return substr($this->input, 0, $position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given token matches the current lookahead.
|
||||
*
|
||||
* @param integer|string $token
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isNextToken($token)
|
||||
{
|
||||
return null !== $this->lookahead && $this->lookahead['type'] === $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether any of the given tokens matches the current lookahead.
|
||||
*
|
||||
* @param array $tokens
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isNextTokenAny(array $tokens)
|
||||
{
|
||||
return null !== $this->lookahead && in_array($this->lookahead['type'], $tokens, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves to the next token in the input string.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveNext()
|
||||
{
|
||||
$this->peek = 0;
|
||||
$this->token = $this->lookahead;
|
||||
$this->lookahead = (isset($this->tokens[$this->position]))
|
||||
? $this->tokens[$this->position++] : null;
|
||||
|
||||
return $this->lookahead !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the lexer to skip input tokens until it sees a token with the given value.
|
||||
*
|
||||
* @param string $type The token type to skip until.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function skipUntil($type)
|
||||
{
|
||||
while ($this->lookahead !== null && $this->lookahead['type'] !== $type) {
|
||||
$this->moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given value is identical to the given token.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param integer $token
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isA($value, $token)
|
||||
{
|
||||
return $this->getType($value) === $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the lookahead token forward.
|
||||
*
|
||||
* @return array|null The next token or NULL if there are no more tokens ahead.
|
||||
*/
|
||||
public function peek()
|
||||
{
|
||||
if (isset($this->tokens[$this->position + $this->peek])) {
|
||||
return $this->tokens[$this->position + $this->peek++];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Peeks at the next token, returns it and immediately resets the peek.
|
||||
*
|
||||
* @return array|null The next token or NULL if there are no more tokens ahead.
|
||||
*/
|
||||
public function glimpse()
|
||||
{
|
||||
$peek = $this->peek();
|
||||
$this->peek = 0;
|
||||
return $peek;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans the input string for tokens.
|
||||
*
|
||||
* @param string $input A query string.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function scan($input)
|
||||
{
|
||||
static $regex;
|
||||
|
||||
if ( ! isset($regex)) {
|
||||
$regex = sprintf(
|
||||
'/(%s)|%s/%s',
|
||||
implode(')|(', $this->getCatchablePatterns()),
|
||||
implode('|', $this->getNonCatchablePatterns()),
|
||||
$this->getModifiers()
|
||||
);
|
||||
}
|
||||
|
||||
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
|
||||
$matches = preg_split($regex, $input, -1, $flags);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
// Must remain before 'value' assignment since it can change content
|
||||
$type = $this->getType($match[0]);
|
||||
|
||||
$this->tokens[] = array(
|
||||
'value' => $match[0],
|
||||
'type' => $type,
|
||||
'position' => $match[1],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the literal for a given token.
|
||||
*
|
||||
* @param integer $token
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLiteral($token)
|
||||
{
|
||||
$className = get_class($this);
|
||||
$reflClass = new \ReflectionClass($className);
|
||||
$constants = $reflClass->getConstants();
|
||||
|
||||
foreach ($constants as $name => $value) {
|
||||
if ($value === $token) {
|
||||
return $className . '::' . $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Regex modifiers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getModifiers()
|
||||
{
|
||||
return 'i';
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexical catchable patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getCatchablePatterns();
|
||||
|
||||
/**
|
||||
* Lexical non-catchable patterns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getNonCatchablePatterns();
|
||||
|
||||
/**
|
||||
* Retrieve token type. Also processes the token value if necessary.
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
abstract protected function getType(&$value);
|
||||
}
|
||||
@@ -16,8 +16,7 @@
|
||||
*/
|
||||
abstract class Swift
|
||||
{
|
||||
/** Swift Mailer Version number generated during dist release process */
|
||||
const VERSION = '@SWIFT_VERSION_NUMBER@';
|
||||
const VERSION = '6.0.2';
|
||||
|
||||
public static $initialized = false;
|
||||
public static $inits = array();
|
||||
@@ -47,7 +46,7 @@ abstract class Swift
|
||||
return;
|
||||
}
|
||||
|
||||
$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
|
||||
$path = __DIR__.'/'.str_replace('_', '/', $class).'.php';
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Attachment class for attaching files to a {@link Swift_Mime_Message}.
|
||||
* Attachment class for attaching files to a {@link Swift_Mime_SimpleMessage}.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
@@ -39,20 +39,6 @@ class Swift_Attachment extends Swift_Mime_Attachment
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Attachment.
|
||||
*
|
||||
* @param string|Swift_OutputByteStream $data
|
||||
* @param string $filename
|
||||
* @param string $contentType
|
||||
*
|
||||
* @return Swift_Mime_Attachment
|
||||
*/
|
||||
public static function newInstance($data = null, $filename = null, $contentType = null)
|
||||
{
|
||||
return new self($data, $filename, $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Attachment from a filesystem path.
|
||||
*
|
||||
@@ -63,7 +49,7 @@ class Swift_Attachment extends Swift_Mime_Attachment
|
||||
*/
|
||||
public static function fromPath($path, $contentType = null)
|
||||
{
|
||||
return self::newInstance()->setFile(
|
||||
return (new self())->setFile(
|
||||
new Swift_ByteStream_FileByteStream($path),
|
||||
$contentType
|
||||
);
|
||||
|
||||
@@ -18,38 +18,38 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
/**
|
||||
* Write sequence.
|
||||
*/
|
||||
protected $_sequence = 0;
|
||||
protected $sequence = 0;
|
||||
|
||||
/**
|
||||
* StreamFilters.
|
||||
*
|
||||
* @var Swift_StreamFilter[]
|
||||
*/
|
||||
private $_filters = array();
|
||||
private $filters = array();
|
||||
|
||||
/**
|
||||
* A buffer for writing.
|
||||
*/
|
||||
private $_writeBuffer = '';
|
||||
private $writeBuffer = '';
|
||||
|
||||
/**
|
||||
* Bound streams.
|
||||
*
|
||||
* @var Swift_InputByteStream[]
|
||||
*/
|
||||
private $_mirrors = array();
|
||||
private $mirrors = array();
|
||||
|
||||
/**
|
||||
* Commit the given bytes to the storage medium immediately.
|
||||
*
|
||||
* @param string $bytes
|
||||
*/
|
||||
abstract protected function _commit($bytes);
|
||||
abstract protected function doCommit($bytes);
|
||||
|
||||
/**
|
||||
* Flush any buffers/content with immediate effect.
|
||||
*/
|
||||
abstract protected function _flush();
|
||||
abstract protected function flush();
|
||||
|
||||
/**
|
||||
* Add a StreamFilter to this InputByteStream.
|
||||
@@ -59,7 +59,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function addFilter(Swift_StreamFilter $filter, $key)
|
||||
{
|
||||
$this->_filters[$key] = $filter;
|
||||
$this->filters[$key] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function removeFilter($key)
|
||||
{
|
||||
unset($this->_filters[$key]);
|
||||
unset($this->filters[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,15 +83,15 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function write($bytes)
|
||||
{
|
||||
$this->_writeBuffer .= $bytes;
|
||||
foreach ($this->_filters as $filter) {
|
||||
if ($filter->shouldBuffer($this->_writeBuffer)) {
|
||||
$this->writeBuffer .= $bytes;
|
||||
foreach ($this->filters as $filter) {
|
||||
if ($filter->shouldBuffer($this->writeBuffer)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->_doWrite($this->_writeBuffer);
|
||||
$this->doWrite($this->writeBuffer);
|
||||
|
||||
return ++$this->_sequence;
|
||||
return ++$this->sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
$this->_doWrite($this->_writeBuffer);
|
||||
$this->doWrite($this->writeBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function bind(Swift_InputByteStream $is)
|
||||
{
|
||||
$this->_mirrors[] = $is;
|
||||
$this->mirrors[] = $is;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,12 +129,12 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function unbind(Swift_InputByteStream $is)
|
||||
{
|
||||
foreach ($this->_mirrors as $k => $stream) {
|
||||
foreach ($this->mirrors as $k => $stream) {
|
||||
if ($is === $stream) {
|
||||
if ($this->_writeBuffer !== '') {
|
||||
$stream->write($this->_writeBuffer);
|
||||
if ($this->writeBuffer !== '') {
|
||||
$stream->write($this->writeBuffer);
|
||||
}
|
||||
unset($this->_mirrors[$k]);
|
||||
unset($this->mirrors[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,20 +147,20 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function flushBuffers()
|
||||
{
|
||||
if ($this->_writeBuffer !== '') {
|
||||
$this->_doWrite($this->_writeBuffer);
|
||||
if ($this->writeBuffer !== '') {
|
||||
$this->doWrite($this->writeBuffer);
|
||||
}
|
||||
$this->_flush();
|
||||
$this->flush();
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->flushBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
/** Run $bytes through all filters */
|
||||
private function _filter($bytes)
|
||||
private function filter($bytes)
|
||||
{
|
||||
foreach ($this->_filters as $filter) {
|
||||
foreach ($this->filters as $filter) {
|
||||
$bytes = $filter->filter($bytes);
|
||||
}
|
||||
|
||||
@@ -168,14 +168,14 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
}
|
||||
|
||||
/** Just write the bytes to the stream */
|
||||
private function _doWrite($bytes)
|
||||
private function doWrite($bytes)
|
||||
{
|
||||
$this->_commit($this->_filter($bytes));
|
||||
$this->doCommit($this->filter($bytes));
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->write($bytes);
|
||||
}
|
||||
|
||||
$this->_writeBuffer = '';
|
||||
$this->writeBuffer = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,28 +20,28 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_array = array();
|
||||
private $array = array();
|
||||
|
||||
/**
|
||||
* The size of the stack.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_arraySize = 0;
|
||||
private $arraySize = 0;
|
||||
|
||||
/**
|
||||
* The internal pointer offset.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_offset = 0;
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* Bound streams.
|
||||
*
|
||||
* @var Swift_InputByteStream[]
|
||||
*/
|
||||
private $_mirrors = array();
|
||||
private $mirrors = array();
|
||||
|
||||
/**
|
||||
* Create a new ArrayByteStream.
|
||||
@@ -53,12 +53,12 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
public function __construct($stack = null)
|
||||
{
|
||||
if (is_array($stack)) {
|
||||
$this->_array = $stack;
|
||||
$this->_arraySize = count($stack);
|
||||
$this->array = $stack;
|
||||
$this->arraySize = count($stack);
|
||||
} elseif (is_string($stack)) {
|
||||
$this->write($stack);
|
||||
} else {
|
||||
$this->_array = array();
|
||||
$this->array = array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,16 +76,16 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->_offset == $this->_arraySize) {
|
||||
if ($this->offset == $this->arraySize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't use array slice
|
||||
$end = $length + $this->_offset;
|
||||
$end = $this->_arraySize < $end ? $this->_arraySize : $end;
|
||||
$end = $length + $this->offset;
|
||||
$end = $this->arraySize < $end ? $this->arraySize : $end;
|
||||
$ret = '';
|
||||
for (; $this->_offset < $end; ++$this->_offset) {
|
||||
$ret .= $this->_array[$this->_offset];
|
||||
for (; $this->offset < $end; ++$this->offset) {
|
||||
$ret .= $this->array[$this->offset];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -100,11 +100,11 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
{
|
||||
$to_add = str_split($bytes);
|
||||
foreach ($to_add as $value) {
|
||||
$this->_array[] = $value;
|
||||
$this->array[] = $value;
|
||||
}
|
||||
$this->_arraySize = count($this->_array);
|
||||
$this->arraySize = count($this->array);
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->write($bytes);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function bind(Swift_InputByteStream $is)
|
||||
{
|
||||
$this->_mirrors[] = $is;
|
||||
$this->mirrors[] = $is;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,9 +140,9 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function unbind(Swift_InputByteStream $is)
|
||||
{
|
||||
foreach ($this->_mirrors as $k => $stream) {
|
||||
foreach ($this->mirrors as $k => $stream) {
|
||||
if ($is === $stream) {
|
||||
unset($this->_mirrors[$k]);
|
||||
unset($this->mirrors[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,13 +156,13 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function setReadPointer($byteOffset)
|
||||
{
|
||||
if ($byteOffset > $this->_arraySize) {
|
||||
$byteOffset = $this->_arraySize;
|
||||
if ($byteOffset > $this->arraySize) {
|
||||
$byteOffset = $this->arraySize;
|
||||
} elseif ($byteOffset < 0) {
|
||||
$byteOffset = 0;
|
||||
}
|
||||
|
||||
$this->_offset = $byteOffset;
|
||||
$this->offset = $byteOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,11 +171,11 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function flushBuffers()
|
||||
{
|
||||
$this->_offset = 0;
|
||||
$this->_array = array();
|
||||
$this->_arraySize = 0;
|
||||
$this->offset = 0;
|
||||
$this->array = array();
|
||||
$this->arraySize = 0;
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->flushBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,25 +16,22 @@
|
||||
class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_FileStream
|
||||
{
|
||||
/** The internal pointer offset */
|
||||
private $_offset = 0;
|
||||
private $offset = 0;
|
||||
|
||||
/** The path to the file */
|
||||
private $_path;
|
||||
private $path;
|
||||
|
||||
/** The mode this file is opened in for writing */
|
||||
private $_mode;
|
||||
private $mode;
|
||||
|
||||
/** A lazy-loaded resource handle for reading the file */
|
||||
private $_reader;
|
||||
private $reader;
|
||||
|
||||
/** A lazy-loaded resource handle for writing the file */
|
||||
private $_writer;
|
||||
|
||||
/** If magic_quotes_runtime is on, this will be true */
|
||||
private $_quotes = false;
|
||||
private $writer;
|
||||
|
||||
/** If stream is seekable true/false, or null if not known */
|
||||
private $_seekable = null;
|
||||
private $seekable = null;
|
||||
|
||||
/**
|
||||
* Create a new FileByteStream for $path.
|
||||
@@ -47,12 +44,8 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
if (empty($path)) {
|
||||
throw new Swift_IoException('The path cannot be empty');
|
||||
}
|
||||
$this->_path = $path;
|
||||
$this->_mode = $writable ? 'w+b' : 'rb';
|
||||
|
||||
if (function_exists('get_magic_quotes_runtime') && @get_magic_quotes_runtime() == 1) {
|
||||
$this->_quotes = true;
|
||||
}
|
||||
$this->path = $path;
|
||||
$this->mode = $writable ? 'w+b' : 'rb';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +55,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,27 +68,21 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @throws Swift_IoException
|
||||
*
|
||||
* @return string|bool
|
||||
*
|
||||
* @throws Swift_IoException
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$fp = $this->_getReadHandle();
|
||||
$fp = $this->getReadHandle();
|
||||
if (!feof($fp)) {
|
||||
if ($this->_quotes) {
|
||||
ini_set('magic_quotes_runtime', 0);
|
||||
}
|
||||
$bytes = fread($fp, $length);
|
||||
if ($this->_quotes) {
|
||||
ini_set('magic_quotes_runtime', 1);
|
||||
}
|
||||
$this->_offset = ftell($fp);
|
||||
$this->offset = ftell($fp);
|
||||
|
||||
// If we read one byte after reaching the end of the file
|
||||
// feof() will return false and an empty string is returned
|
||||
if ($bytes === '' && feof($fp)) {
|
||||
$this->_resetReadHandle();
|
||||
$this->resetReadHandle();
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -103,7 +90,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
$this->_resetReadHandle();
|
||||
$this->resetReadHandle();
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -117,93 +104,93 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
*/
|
||||
public function setReadPointer($byteOffset)
|
||||
{
|
||||
if (isset($this->_reader)) {
|
||||
$this->_seekReadStreamToPosition($byteOffset);
|
||||
if (isset($this->reader)) {
|
||||
$this->seekReadStreamToPosition($byteOffset);
|
||||
}
|
||||
$this->_offset = $byteOffset;
|
||||
$this->offset = $byteOffset;
|
||||
}
|
||||
|
||||
/** Just write the bytes to the file */
|
||||
protected function _commit($bytes)
|
||||
protected function doCommit($bytes)
|
||||
{
|
||||
fwrite($this->_getWriteHandle(), $bytes);
|
||||
$this->_resetReadHandle();
|
||||
fwrite($this->getWriteHandle(), $bytes);
|
||||
$this->resetReadHandle();
|
||||
}
|
||||
|
||||
/** Not used */
|
||||
protected function _flush()
|
||||
protected function flush()
|
||||
{
|
||||
}
|
||||
|
||||
/** Get the resource for reading */
|
||||
private function _getReadHandle()
|
||||
private function getReadHandle()
|
||||
{
|
||||
if (!isset($this->_reader)) {
|
||||
if (!$this->_reader = fopen($this->_path, 'rb')) {
|
||||
throw new Swift_IoException(
|
||||
'Unable to open file for reading ['.$this->_path.']'
|
||||
);
|
||||
if (!isset($this->reader)) {
|
||||
$pointer = @fopen($this->path, 'rb');
|
||||
if (!$pointer) {
|
||||
throw new Swift_IoException('Unable to open file for reading ['.$this->path.']');
|
||||
}
|
||||
if ($this->_offset != 0) {
|
||||
$this->_getReadStreamSeekableStatus();
|
||||
$this->_seekReadStreamToPosition($this->_offset);
|
||||
$this->reader = $pointer;
|
||||
if ($this->offset != 0) {
|
||||
$this->getReadStreamSeekableStatus();
|
||||
$this->seekReadStreamToPosition($this->offset);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_reader;
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
/** Get the resource for writing */
|
||||
private function _getWriteHandle()
|
||||
private function getWriteHandle()
|
||||
{
|
||||
if (!isset($this->_writer)) {
|
||||
if (!$this->_writer = fopen($this->_path, $this->_mode)) {
|
||||
if (!isset($this->writer)) {
|
||||
if (!$this->writer = fopen($this->path, $this->mode)) {
|
||||
throw new Swift_IoException(
|
||||
'Unable to open file for writing ['.$this->_path.']'
|
||||
'Unable to open file for writing ['.$this->path.']'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_writer;
|
||||
return $this->writer;
|
||||
}
|
||||
|
||||
/** Force a reload of the resource for reading */
|
||||
private function _resetReadHandle()
|
||||
private function resetReadHandle()
|
||||
{
|
||||
if (isset($this->_reader)) {
|
||||
fclose($this->_reader);
|
||||
$this->_reader = null;
|
||||
if (isset($this->reader)) {
|
||||
fclose($this->reader);
|
||||
$this->reader = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if ReadOnly Stream is seekable */
|
||||
private function _getReadStreamSeekableStatus()
|
||||
private function getReadStreamSeekableStatus()
|
||||
{
|
||||
$metas = stream_get_meta_data($this->_reader);
|
||||
$this->_seekable = $metas['seekable'];
|
||||
$metas = stream_get_meta_data($this->reader);
|
||||
$this->seekable = $metas['seekable'];
|
||||
}
|
||||
|
||||
/** Streams in a readOnly stream ensuring copy if needed */
|
||||
private function _seekReadStreamToPosition($offset)
|
||||
private function seekReadStreamToPosition($offset)
|
||||
{
|
||||
if ($this->_seekable === null) {
|
||||
$this->_getReadStreamSeekableStatus();
|
||||
if ($this->seekable === null) {
|
||||
$this->getReadStreamSeekableStatus();
|
||||
}
|
||||
if ($this->_seekable === false) {
|
||||
$currentPos = ftell($this->_reader);
|
||||
if ($this->seekable === false) {
|
||||
$currentPos = ftell($this->reader);
|
||||
if ($currentPos < $offset) {
|
||||
$toDiscard = $offset - $currentPos;
|
||||
fread($this->_reader, $toDiscard);
|
||||
fread($this->reader, $toDiscard);
|
||||
|
||||
return;
|
||||
}
|
||||
$this->_copyReadStream();
|
||||
$this->copyReadStream();
|
||||
}
|
||||
fseek($this->_reader, $offset, SEEK_SET);
|
||||
fseek($this->reader, $offset, SEEK_SET);
|
||||
}
|
||||
|
||||
/** Copy a readOnly Stream to ensure seekability */
|
||||
private function _copyReadStream()
|
||||
private function copyReadStream()
|
||||
{
|
||||
if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b')) {
|
||||
/* We have opened a php:// Stream Should work without problem */
|
||||
@@ -212,11 +199,11 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
} else {
|
||||
throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');
|
||||
}
|
||||
$currentPos = ftell($this->_reader);
|
||||
fclose($this->_reader);
|
||||
$source = fopen($this->_path, 'rb');
|
||||
$currentPos = ftell($this->reader);
|
||||
fclose($this->reader);
|
||||
$source = fopen($this->path, 'rb');
|
||||
if (!$source) {
|
||||
throw new Swift_IoException('Unable to open file for copying ['.$this->_path.']');
|
||||
throw new Swift_IoException('Unable to open file for copying ['.$this->path.']');
|
||||
}
|
||||
fseek($tmpFile, 0, SEEK_SET);
|
||||
while (!feof($source)) {
|
||||
@@ -224,6 +211,6 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
}
|
||||
fseek($tmpFile, $currentPos, SEEK_SET);
|
||||
fclose($source);
|
||||
$this->_reader = $tmpFile;
|
||||
$this->reader = $tmpFile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ interface Swift_CharacterReader
|
||||
* A value of zero means this is already a valid character.
|
||||
* A value of -1 means this cannot possibly be a valid character.
|
||||
*
|
||||
* @param integer[] $bytes
|
||||
* @param int[] $bytes
|
||||
* @param int $size
|
||||
*
|
||||
* @return int
|
||||
|
||||
@@ -21,7 +21,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_width;
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* Creates a new GenericFixedWidthReader using $width bytes per character.
|
||||
@@ -30,7 +30,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
|
||||
*/
|
||||
public function __construct($width)
|
||||
{
|
||||
$this->_width = $width;
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,11 +47,11 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
|
||||
{
|
||||
$strlen = strlen($string);
|
||||
// % and / are CPU intensive, so, maybe find a better way
|
||||
$ignored = $strlen % $this->_width;
|
||||
$ignoredChars = substr($string, -$ignored);
|
||||
$currentMap = $this->_width;
|
||||
$ignored = $strlen % $this->width;
|
||||
$ignoredChars = $ignored ? substr($string, -$ignored) : '';
|
||||
$currentMap = $this->width;
|
||||
|
||||
return ($strlen - $ignored) / $this->_width;
|
||||
return ($strlen - $ignored) / $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
|
||||
*/
|
||||
public function validateByteSequence($bytes, $size)
|
||||
{
|
||||
$needed = $this->_width - $size;
|
||||
$needed = $this->width - $size;
|
||||
|
||||
return $needed > -1 ? $needed : -1;
|
||||
}
|
||||
@@ -92,6 +92,6 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
|
||||
*/
|
||||
public function getInitialByteSize()
|
||||
{
|
||||
return $this->_width;
|
||||
return $this->width;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
|
||||
/** Pre-computed for optimization */
|
||||
private static $length_map = array(
|
||||
// N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x0N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x2N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x4N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x6N
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7N
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x8N
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9N
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xAN
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBN
|
||||
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xCN
|
||||
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDN
|
||||
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEN
|
||||
4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0, // 0xFN
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN
|
||||
4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN
|
||||
);
|
||||
|
||||
private static $s_length_map = array(
|
||||
|
||||
@@ -20,14 +20,14 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $_map = array();
|
||||
private static $map = array();
|
||||
|
||||
/**
|
||||
* Factories which have already been loaded.
|
||||
*
|
||||
* @var Swift_CharacterReaderFactory[]
|
||||
*/
|
||||
private static $_loaded = array();
|
||||
private static $loaded = array();
|
||||
|
||||
/**
|
||||
* Creates a new CharacterReaderFactory.
|
||||
@@ -44,7 +44,7 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
|
||||
|
||||
public function init()
|
||||
{
|
||||
if (count(self::$_map) > 0) {
|
||||
if (count(self::$map) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,32 +66,32 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
|
||||
);
|
||||
|
||||
// Utf-8
|
||||
self::$_map['utf-?8'] = array(
|
||||
self::$map['utf-?8'] = array(
|
||||
'class' => $prefix.'Utf8Reader',
|
||||
'constructor' => array(),
|
||||
);
|
||||
|
||||
//7-8 bit charsets
|
||||
self::$_map['(us-)?ascii'] = $singleByte;
|
||||
self::$_map['(iso|iec)-?8859-?[0-9]+'] = $singleByte;
|
||||
self::$_map['windows-?125[0-9]'] = $singleByte;
|
||||
self::$_map['cp-?[0-9]+'] = $singleByte;
|
||||
self::$_map['ansi'] = $singleByte;
|
||||
self::$_map['macintosh'] = $singleByte;
|
||||
self::$_map['koi-?7'] = $singleByte;
|
||||
self::$_map['koi-?8-?.+'] = $singleByte;
|
||||
self::$_map['mik'] = $singleByte;
|
||||
self::$_map['(cork|t1)'] = $singleByte;
|
||||
self::$_map['v?iscii'] = $singleByte;
|
||||
self::$map['(us-)?ascii'] = $singleByte;
|
||||
self::$map['(iso|iec)-?8859-?[0-9]+'] = $singleByte;
|
||||
self::$map['windows-?125[0-9]'] = $singleByte;
|
||||
self::$map['cp-?[0-9]+'] = $singleByte;
|
||||
self::$map['ansi'] = $singleByte;
|
||||
self::$map['macintosh'] = $singleByte;
|
||||
self::$map['koi-?7'] = $singleByte;
|
||||
self::$map['koi-?8-?.+'] = $singleByte;
|
||||
self::$map['mik'] = $singleByte;
|
||||
self::$map['(cork|t1)'] = $singleByte;
|
||||
self::$map['v?iscii'] = $singleByte;
|
||||
|
||||
//16 bits
|
||||
self::$_map['(ucs-?2|utf-?16)'] = $doubleByte;
|
||||
self::$map['(ucs-?2|utf-?16)'] = $doubleByte;
|
||||
|
||||
//32 bits
|
||||
self::$_map['(ucs-?4|utf-?32)'] = $fourBytes;
|
||||
self::$map['(ucs-?4|utf-?32)'] = $fourBytes;
|
||||
|
||||
// Fallback
|
||||
self::$_map['.*'] = $singleByte;
|
||||
self::$map['.*'] = $singleByte;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,21 +103,21 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
|
||||
*/
|
||||
public function getReaderFor($charset)
|
||||
{
|
||||
$charset = trim(strtolower($charset));
|
||||
foreach (self::$_map as $pattern => $spec) {
|
||||
$charset = strtolower(trim($charset));
|
||||
foreach (self::$map as $pattern => $spec) {
|
||||
$re = '/^'.$pattern.'$/D';
|
||||
if (preg_match($re, $charset)) {
|
||||
if (!array_key_exists($pattern, self::$_loaded)) {
|
||||
if (!array_key_exists($pattern, self::$loaded)) {
|
||||
$reflector = new ReflectionClass($spec['class']);
|
||||
if ($reflector->getConstructor()) {
|
||||
$reader = $reflector->newInstanceArgs($spec['constructor']);
|
||||
} else {
|
||||
$reader = $reflector->newInstance();
|
||||
}
|
||||
self::$_loaded[$pattern] = $reader;
|
||||
self::$loaded[$pattern] = $reader;
|
||||
}
|
||||
|
||||
return self::$_loaded[$pattern];
|
||||
return self::$loaded[$pattern];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,28 +16,28 @@
|
||||
class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStream
|
||||
{
|
||||
/** A map of byte values and their respective characters */
|
||||
private static $_charMap;
|
||||
private static $charMap;
|
||||
|
||||
/** A map of characters and their derivative byte values */
|
||||
private static $_byteMap;
|
||||
private static $byteMap;
|
||||
|
||||
/** The char reader (lazy-loaded) for the current charset */
|
||||
private $_charReader;
|
||||
private $charReader;
|
||||
|
||||
/** A factory for creating CharacterReader instances */
|
||||
private $_charReaderFactory;
|
||||
private $charReaderFactory;
|
||||
|
||||
/** The character set this stream is using */
|
||||
private $_charset;
|
||||
private $charset;
|
||||
|
||||
/** Array of characters */
|
||||
private $_array = array();
|
||||
private $array = array();
|
||||
|
||||
/** Size of the array of character */
|
||||
private $_array_size = array();
|
||||
private $array_size = array();
|
||||
|
||||
/** The current character offset in the stream */
|
||||
private $_offset = 0;
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* Create a new CharacterStream with the given $chars, if set.
|
||||
@@ -47,7 +47,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function __construct(Swift_CharacterReaderFactory $factory, $charset)
|
||||
{
|
||||
self::_initializeMaps();
|
||||
self::initializeMaps();
|
||||
$this->setCharacterReaderFactory($factory);
|
||||
$this->setCharacterSet($charset);
|
||||
}
|
||||
@@ -59,8 +59,8 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function setCharacterSet($charset)
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_charReader = null;
|
||||
$this->charset = $charset;
|
||||
$this->charReader = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
|
||||
{
|
||||
$this->_charReaderFactory = $factory;
|
||||
$this->charReaderFactory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,28 +80,28 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function importByteStream(Swift_OutputByteStream $os)
|
||||
{
|
||||
if (!isset($this->_charReader)) {
|
||||
$this->_charReader = $this->_charReaderFactory
|
||||
->getReaderFor($this->_charset);
|
||||
if (!isset($this->charReader)) {
|
||||
$this->charReader = $this->charReaderFactory
|
||||
->getReaderFor($this->charset);
|
||||
}
|
||||
|
||||
$startLength = $this->_charReader->getInitialByteSize();
|
||||
$startLength = $this->charReader->getInitialByteSize();
|
||||
while (false !== $bytes = $os->read($startLength)) {
|
||||
$c = array();
|
||||
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
|
||||
$c[] = self::$_byteMap[$bytes[$i]];
|
||||
$c[] = self::$byteMap[$bytes[$i]];
|
||||
}
|
||||
$size = count($c);
|
||||
$need = $this->_charReader
|
||||
$need = $this->charReader
|
||||
->validateByteSequence($c, $size);
|
||||
if ($need > 0 &&
|
||||
false !== $bytes = $os->read($need)) {
|
||||
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
|
||||
$c[] = self::$_byteMap[$bytes[$i]];
|
||||
$c[] = self::$byteMap[$bytes[$i]];
|
||||
}
|
||||
}
|
||||
$this->_array[] = $c;
|
||||
++$this->_array_size;
|
||||
$this->array[] = $c;
|
||||
++$this->array_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,20 +127,20 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->_offset == $this->_array_size) {
|
||||
if ($this->offset == $this->array_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't use array slice
|
||||
$arrays = array();
|
||||
$end = $length + $this->_offset;
|
||||
for ($i = $this->_offset; $i < $end; ++$i) {
|
||||
if (!isset($this->_array[$i])) {
|
||||
$end = $length + $this->offset;
|
||||
for ($i = $this->offset; $i < $end; ++$i) {
|
||||
if (!isset($this->array[$i])) {
|
||||
break;
|
||||
}
|
||||
$arrays[] = $this->_array[$i];
|
||||
$arrays[] = $this->array[$i];
|
||||
}
|
||||
$this->_offset += $i - $this->_offset; // Limit function calls
|
||||
$this->offset += $i - $this->offset; // Limit function calls
|
||||
$chars = false;
|
||||
foreach ($arrays as $array) {
|
||||
$chars .= implode('', array_map('chr', $array));
|
||||
@@ -155,24 +155,24 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return integer[]
|
||||
* @return int[]
|
||||
*/
|
||||
public function readBytes($length)
|
||||
{
|
||||
if ($this->_offset == $this->_array_size) {
|
||||
if ($this->offset == $this->array_size) {
|
||||
return false;
|
||||
}
|
||||
$arrays = array();
|
||||
$end = $length + $this->_offset;
|
||||
for ($i = $this->_offset; $i < $end; ++$i) {
|
||||
if (!isset($this->_array[$i])) {
|
||||
$end = $length + $this->offset;
|
||||
for ($i = $this->offset; $i < $end; ++$i) {
|
||||
if (!isset($this->array[$i])) {
|
||||
break;
|
||||
}
|
||||
$arrays[] = $this->_array[$i];
|
||||
$arrays[] = $this->array[$i];
|
||||
}
|
||||
$this->_offset += ($i - $this->_offset); // Limit function calls
|
||||
$this->offset += ($i - $this->offset); // Limit function calls
|
||||
|
||||
return call_user_func_array('array_merge', $arrays);
|
||||
return array_merge(...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,12 +182,12 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function write($chars)
|
||||
{
|
||||
if (!isset($this->_charReader)) {
|
||||
$this->_charReader = $this->_charReaderFactory->getReaderFor(
|
||||
$this->_charset);
|
||||
if (!isset($this->charReader)) {
|
||||
$this->charReader = $this->charReaderFactory->getReaderFor(
|
||||
$this->charset);
|
||||
}
|
||||
|
||||
$startLength = $this->_charReader->getInitialByteSize();
|
||||
$startLength = $this->charReader->getInitialByteSize();
|
||||
|
||||
$fp = fopen('php://memory', 'w+b');
|
||||
fwrite($fp, $chars);
|
||||
@@ -203,7 +203,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
// Buffer Filing
|
||||
if ($buf_len - $buf_pos < $startLength) {
|
||||
$buf = array_splice($buffer, $buf_pos);
|
||||
$new = $this->_reloadBuffer($fp, 100);
|
||||
$new = $this->reloadBuffer($fp, 100);
|
||||
if ($new) {
|
||||
$buffer = array_merge($buf, $new);
|
||||
$buf_len = count($buffer);
|
||||
@@ -218,11 +218,11 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
++$size;
|
||||
$bytes[] = $buffer[$buf_pos++];
|
||||
}
|
||||
$need = $this->_charReader->validateByteSequence(
|
||||
$need = $this->charReader->validateByteSequence(
|
||||
$bytes, $size);
|
||||
if ($need > 0) {
|
||||
if ($buf_len - $buf_pos < $need) {
|
||||
$new = $this->_reloadBuffer($fp, $need);
|
||||
$new = $this->reloadBuffer($fp, $need);
|
||||
|
||||
if ($new) {
|
||||
$buffer = array_merge($buffer, $new);
|
||||
@@ -233,8 +233,8 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
$bytes[] = $buffer[$buf_pos++];
|
||||
}
|
||||
}
|
||||
$this->_array[] = $bytes;
|
||||
++$this->_array_size;
|
||||
$this->array[] = $bytes;
|
||||
++$this->array_size;
|
||||
}
|
||||
} while ($has_datas);
|
||||
|
||||
@@ -248,12 +248,12 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function setPointer($charOffset)
|
||||
{
|
||||
if ($charOffset > $this->_array_size) {
|
||||
$charOffset = $this->_array_size;
|
||||
if ($charOffset > $this->array_size) {
|
||||
$charOffset = $this->array_size;
|
||||
} elseif ($charOffset < 0) {
|
||||
$charOffset = 0;
|
||||
}
|
||||
$this->_offset = $charOffset;
|
||||
$this->offset = $charOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,17 +261,17 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function flushContents()
|
||||
{
|
||||
$this->_offset = 0;
|
||||
$this->_array = array();
|
||||
$this->_array_size = 0;
|
||||
$this->offset = 0;
|
||||
$this->array = array();
|
||||
$this->array_size = 0;
|
||||
}
|
||||
|
||||
private function _reloadBuffer($fp, $len)
|
||||
private function reloadBuffer($fp, $len)
|
||||
{
|
||||
if (!feof($fp) && ($bytes = fread($fp, $len)) !== false) {
|
||||
$buf = array();
|
||||
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
|
||||
$buf[] = self::$_byteMap[$bytes[$i]];
|
||||
$buf[] = self::$byteMap[$bytes[$i]];
|
||||
}
|
||||
|
||||
return $buf;
|
||||
@@ -280,14 +280,14 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function _initializeMaps()
|
||||
private static function initializeMaps()
|
||||
{
|
||||
if (!isset(self::$_charMap)) {
|
||||
self::$_charMap = array();
|
||||
if (!isset(self::$charMap)) {
|
||||
self::$charMap = array();
|
||||
for ($byte = 0; $byte < 256; ++$byte) {
|
||||
self::$_charMap[$byte] = chr($byte);
|
||||
self::$charMap[$byte] = chr($byte);
|
||||
}
|
||||
self::$_byteMap = array_flip(self::$_charMap);
|
||||
self::$byteMap = array_flip(self::$charMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,63 +20,63 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*
|
||||
* @var Swift_CharacterReader
|
||||
*/
|
||||
private $_charReader;
|
||||
private $charReader;
|
||||
|
||||
/**
|
||||
* A factory for creating CharacterReader instances.
|
||||
*
|
||||
* @var Swift_CharacterReaderFactory
|
||||
*/
|
||||
private $_charReaderFactory;
|
||||
private $charReaderFactory;
|
||||
|
||||
/**
|
||||
* The character set this stream is using.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_charset;
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* The data's stored as-is.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_datas = '';
|
||||
private $datas = '';
|
||||
|
||||
/**
|
||||
* Number of bytes in the stream.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_datasSize = 0;
|
||||
private $datasSize = 0;
|
||||
|
||||
/**
|
||||
* Map.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_map;
|
||||
private $map;
|
||||
|
||||
/**
|
||||
* Map Type.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_mapType = 0;
|
||||
private $mapType = 0;
|
||||
|
||||
/**
|
||||
* Number of characters in the stream.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_charCount = 0;
|
||||
private $charCount = 0;
|
||||
|
||||
/**
|
||||
* Position in the stream.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_currentPos = 0;
|
||||
private $currentPos = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -99,9 +99,9 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function setCharacterSet($charset)
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_charReader = null;
|
||||
$this->_mapType = 0;
|
||||
$this->charset = $charset;
|
||||
$this->charReader = null;
|
||||
$this->mapType = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
|
||||
{
|
||||
$this->_charReaderFactory = $factory;
|
||||
$this->charReaderFactory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,11 +119,11 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function flushContents()
|
||||
{
|
||||
$this->_datas = null;
|
||||
$this->_map = null;
|
||||
$this->_charCount = 0;
|
||||
$this->_currentPos = 0;
|
||||
$this->_datasSize = 0;
|
||||
$this->datas = null;
|
||||
$this->map = null;
|
||||
$this->charCount = 0;
|
||||
$this->currentPos = 0;
|
||||
$this->datasSize = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,49 +161,49 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->_currentPos >= $this->_charCount) {
|
||||
if ($this->currentPos >= $this->charCount) {
|
||||
return false;
|
||||
}
|
||||
$ret = false;
|
||||
$length = $this->_currentPos + $length > $this->_charCount ? $this->_charCount - $this->_currentPos : $length;
|
||||
switch ($this->_mapType) {
|
||||
$length = ($this->currentPos + $length > $this->charCount) ? $this->charCount - $this->currentPos : $length;
|
||||
switch ($this->mapType) {
|
||||
case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
|
||||
$len = $length * $this->_map;
|
||||
$ret = substr($this->_datas,
|
||||
$this->_currentPos * $this->_map,
|
||||
$len = $length * $this->map;
|
||||
$ret = substr($this->datas,
|
||||
$this->currentPos * $this->map,
|
||||
$len);
|
||||
$this->_currentPos += $length;
|
||||
$this->currentPos += $length;
|
||||
break;
|
||||
|
||||
case Swift_CharacterReader::MAP_TYPE_INVALID:
|
||||
$ret = '';
|
||||
for (; $this->_currentPos < $length; ++$this->_currentPos) {
|
||||
if (isset($this->_map[$this->_currentPos])) {
|
||||
for (; $this->currentPos < $length; ++$this->currentPos) {
|
||||
if (isset($this->map[$this->currentPos])) {
|
||||
$ret .= '?';
|
||||
} else {
|
||||
$ret .= $this->_datas[$this->_currentPos];
|
||||
$ret .= $this->datas[$this->currentPos];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Swift_CharacterReader::MAP_TYPE_POSITIONS:
|
||||
$end = $this->_currentPos + $length;
|
||||
$end = $end > $this->_charCount ? $this->_charCount : $end;
|
||||
$end = $this->currentPos + $length;
|
||||
$end = $end > $this->charCount ? $this->charCount : $end;
|
||||
$ret = '';
|
||||
$start = 0;
|
||||
if ($this->_currentPos > 0) {
|
||||
$start = $this->_map['p'][$this->_currentPos - 1];
|
||||
if ($this->currentPos > 0) {
|
||||
$start = $this->map['p'][$this->currentPos - 1];
|
||||
}
|
||||
$to = $start;
|
||||
for (; $this->_currentPos < $end; ++$this->_currentPos) {
|
||||
if (isset($this->_map['i'][$this->_currentPos])) {
|
||||
$ret .= substr($this->_datas, $start, $to - $start).'?';
|
||||
$start = $this->_map['p'][$this->_currentPos];
|
||||
for (; $this->currentPos < $end; ++$this->currentPos) {
|
||||
if (isset($this->map['i'][$this->currentPos])) {
|
||||
$ret .= substr($this->datas, $start, $to - $start).'?';
|
||||
$start = $this->map['p'][$this->currentPos];
|
||||
} else {
|
||||
$to = $this->_map['p'][$this->_currentPos];
|
||||
$to = $this->map['p'][$this->currentPos];
|
||||
}
|
||||
}
|
||||
$ret .= substr($this->_datas, $start, $to - $start);
|
||||
$ret .= substr($this->datas, $start, $to - $start);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return integer[]
|
||||
* @return int[]
|
||||
*/
|
||||
public function readBytes($length)
|
||||
{
|
||||
@@ -236,10 +236,10 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function setPointer($charOffset)
|
||||
{
|
||||
if ($this->_charCount < $charOffset) {
|
||||
$charOffset = $this->_charCount;
|
||||
if ($this->charCount < $charOffset) {
|
||||
$charOffset = $this->charCount;
|
||||
}
|
||||
$this->_currentPos = $charOffset;
|
||||
$this->currentPos = $charOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,19 +249,19 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function write($chars)
|
||||
{
|
||||
if (!isset($this->_charReader)) {
|
||||
$this->_charReader = $this->_charReaderFactory->getReaderFor(
|
||||
$this->_charset);
|
||||
$this->_map = array();
|
||||
$this->_mapType = $this->_charReader->getMapType();
|
||||
if (!isset($this->charReader)) {
|
||||
$this->charReader = $this->charReaderFactory->getReaderFor(
|
||||
$this->charset);
|
||||
$this->map = array();
|
||||
$this->mapType = $this->charReader->getMapType();
|
||||
}
|
||||
$ignored = '';
|
||||
$this->_datas .= $chars;
|
||||
$this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored);
|
||||
$this->datas .= $chars;
|
||||
$this->charCount += $this->charReader->getCharPositions(substr($this->datas, $this->datasSize), $this->datasSize, $this->map, $ignored);
|
||||
if ($ignored !== false) {
|
||||
$this->_datasSize = strlen($this->_datas) - strlen($ignored);
|
||||
$this->datasSize = strlen($this->datas) - strlen($ignored);
|
||||
} else {
|
||||
$this->_datasSize = strlen($this->_datas);
|
||||
$this->datasSize = strlen($this->datas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
abstract class Swift_ConfigurableSpool implements Swift_Spool
|
||||
{
|
||||
/** The maximum number of messages to send per flush */
|
||||
private $_message_limit;
|
||||
private $message_limit;
|
||||
|
||||
/** The time limit per flush */
|
||||
private $_time_limit;
|
||||
private $time_limit;
|
||||
|
||||
/**
|
||||
* Sets the maximum number of messages to send per flush.
|
||||
@@ -28,7 +28,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
|
||||
*/
|
||||
public function setMessageLimit($limit)
|
||||
{
|
||||
$this->_message_limit = (int) $limit;
|
||||
$this->message_limit = (int) $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
|
||||
*/
|
||||
public function getMessageLimit()
|
||||
{
|
||||
return $this->_message_limit;
|
||||
return $this->message_limit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
|
||||
*/
|
||||
public function setTimeLimit($limit)
|
||||
{
|
||||
$this->_time_limit = (int) $limit;
|
||||
$this->time_limit = (int) $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +58,6 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool
|
||||
*/
|
||||
public function getTimeLimit()
|
||||
{
|
||||
return $this->_time_limit;
|
||||
return $this->time_limit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ class Swift_DependencyContainer
|
||||
const TYPE_ALIAS = 0x1000;
|
||||
|
||||
/** Singleton instance */
|
||||
private static $_instance = null;
|
||||
private static $instance = null;
|
||||
|
||||
/** The data container */
|
||||
private $_store = array();
|
||||
private $store = array();
|
||||
|
||||
/** The current endpoint in the data container */
|
||||
private $_endPoint;
|
||||
private $endPoint;
|
||||
|
||||
/**
|
||||
* Constructor should not be used.
|
||||
@@ -48,15 +48,15 @@ class Swift_DependencyContainer
|
||||
/**
|
||||
* Returns a singleton of the DependencyContainer.
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return self
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!isset(self::$_instance)) {
|
||||
self::$_instance = new self();
|
||||
if (!isset(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +66,7 @@ class Swift_DependencyContainer
|
||||
*/
|
||||
public function listItems()
|
||||
{
|
||||
return array_keys($this->_store);
|
||||
return array_keys($this->store);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,8 +80,8 @@ class Swift_DependencyContainer
|
||||
*/
|
||||
public function has($itemName)
|
||||
{
|
||||
return array_key_exists($itemName, $this->_store)
|
||||
&& isset($this->_store[$itemName]['lookupType']);
|
||||
return array_key_exists($itemName, $this->store)
|
||||
&& isset($this->store[$itemName]['lookupType']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,9 +91,9 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param string $itemName
|
||||
*
|
||||
* @throws Swift_DependencyException If the dependency is not found
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws Swift_DependencyException If the dependency is not found
|
||||
*/
|
||||
public function lookup($itemName)
|
||||
{
|
||||
@@ -103,15 +103,15 @@ class Swift_DependencyContainer
|
||||
);
|
||||
}
|
||||
|
||||
switch ($this->_store[$itemName]['lookupType']) {
|
||||
switch ($this->store[$itemName]['lookupType']) {
|
||||
case self::TYPE_ALIAS:
|
||||
return $this->_createAlias($itemName);
|
||||
return $this->createAlias($itemName);
|
||||
case self::TYPE_VALUE:
|
||||
return $this->_getValue($itemName);
|
||||
return $this->getValue($itemName);
|
||||
case self::TYPE_INSTANCE:
|
||||
return $this->_createNewInstance($itemName);
|
||||
return $this->createNewInstance($itemName);
|
||||
case self::TYPE_SHARED:
|
||||
return $this->_createSharedInstance($itemName);
|
||||
return $this->createSharedInstance($itemName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,8 +125,8 @@ class Swift_DependencyContainer
|
||||
public function createDependenciesFor($itemName)
|
||||
{
|
||||
$args = array();
|
||||
if (isset($this->_store[$itemName]['args'])) {
|
||||
$args = $this->_resolveArgs($this->_store[$itemName]['args']);
|
||||
if (isset($this->store[$itemName]['args'])) {
|
||||
$args = $this->resolveArgs($this->store[$itemName]['args']);
|
||||
}
|
||||
|
||||
return $args;
|
||||
@@ -143,12 +143,12 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param string $itemName
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function register($itemName)
|
||||
{
|
||||
$this->_store[$itemName] = array();
|
||||
$this->_endPoint = &$this->_store[$itemName];
|
||||
$this->store[$itemName] = array();
|
||||
$this->endPoint = &$this->store[$itemName];
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -160,11 +160,11 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function asValue($value)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
$endPoint = &$this->getEndPoint();
|
||||
$endPoint['lookupType'] = self::TYPE_VALUE;
|
||||
$endPoint['value'] = $value;
|
||||
|
||||
@@ -176,11 +176,11 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param string $lookup
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function asAliasOf($lookup)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
$endPoint = &$this->getEndPoint();
|
||||
$endPoint['lookupType'] = self::TYPE_ALIAS;
|
||||
$endPoint['ref'] = $lookup;
|
||||
|
||||
@@ -198,11 +198,11 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function asNewInstanceOf($className)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
$endPoint = &$this->getEndPoint();
|
||||
$endPoint['lookupType'] = self::TYPE_INSTANCE;
|
||||
$endPoint['className'] = $className;
|
||||
|
||||
@@ -216,11 +216,11 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param string $className
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function asSharedInstanceOf($className)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
$endPoint = &$this->getEndPoint();
|
||||
$endPoint['lookupType'] = self::TYPE_SHARED;
|
||||
$endPoint['className'] = $className;
|
||||
|
||||
@@ -236,11 +236,11 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param array $lookups
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function withDependencies(array $lookups)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
$endPoint = &$this->getEndPoint();
|
||||
$endPoint['args'] = array();
|
||||
foreach ($lookups as $lookup) {
|
||||
$this->addConstructorLookup($lookup);
|
||||
@@ -257,11 +257,11 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function addConstructorValue($value)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
$endPoint = &$this->getEndPoint();
|
||||
if (!isset($endPoint['args'])) {
|
||||
$endPoint['args'] = array();
|
||||
}
|
||||
@@ -278,12 +278,12 @@ class Swift_DependencyContainer
|
||||
*
|
||||
* @param string $lookup
|
||||
*
|
||||
* @return Swift_DependencyContainer
|
||||
* @return $this
|
||||
*/
|
||||
public function addConstructorLookup($lookup)
|
||||
{
|
||||
$endPoint = &$this->_getEndPoint();
|
||||
if (!isset($this->_endPoint['args'])) {
|
||||
$endPoint = &$this->getEndPoint();
|
||||
if (!isset($this->endPoint['args'])) {
|
||||
$endPoint['args'] = array();
|
||||
}
|
||||
$endPoint['args'][] = array('type' => 'lookup', 'item' => $lookup);
|
||||
@@ -292,21 +292,21 @@ class Swift_DependencyContainer
|
||||
}
|
||||
|
||||
/** Get the literal value with $itemName */
|
||||
private function _getValue($itemName)
|
||||
private function getValue($itemName)
|
||||
{
|
||||
return $this->_store[$itemName]['value'];
|
||||
return $this->store[$itemName]['value'];
|
||||
}
|
||||
|
||||
/** Resolve an alias to another item */
|
||||
private function _createAlias($itemName)
|
||||
private function createAlias($itemName)
|
||||
{
|
||||
return $this->lookup($this->_store[$itemName]['ref']);
|
||||
return $this->lookup($this->store[$itemName]['ref']);
|
||||
}
|
||||
|
||||
/** Create a fresh instance of $itemName */
|
||||
private function _createNewInstance($itemName)
|
||||
private function createNewInstance($itemName)
|
||||
{
|
||||
$reflector = new ReflectionClass($this->_store[$itemName]['className']);
|
||||
$reflector = new ReflectionClass($this->store[$itemName]['className']);
|
||||
if ($reflector->getConstructor()) {
|
||||
return $reflector->newInstanceArgs(
|
||||
$this->createDependenciesFor($itemName)
|
||||
@@ -317,35 +317,35 @@ class Swift_DependencyContainer
|
||||
}
|
||||
|
||||
/** Create and register a shared instance of $itemName */
|
||||
private function _createSharedInstance($itemName)
|
||||
private function createSharedInstance($itemName)
|
||||
{
|
||||
if (!isset($this->_store[$itemName]['instance'])) {
|
||||
$this->_store[$itemName]['instance'] = $this->_createNewInstance($itemName);
|
||||
if (!isset($this->store[$itemName]['instance'])) {
|
||||
$this->store[$itemName]['instance'] = $this->createNewInstance($itemName);
|
||||
}
|
||||
|
||||
return $this->_store[$itemName]['instance'];
|
||||
return $this->store[$itemName]['instance'];
|
||||
}
|
||||
|
||||
/** Get the current endpoint in the store */
|
||||
private function &_getEndPoint()
|
||||
private function &getEndPoint()
|
||||
{
|
||||
if (!isset($this->_endPoint)) {
|
||||
if (!isset($this->endPoint)) {
|
||||
throw new BadMethodCallException(
|
||||
'Component must first be registered by calling register()'
|
||||
);
|
||||
}
|
||||
|
||||
return $this->_endPoint;
|
||||
return $this->endPoint;
|
||||
}
|
||||
|
||||
/** Get an argument list with dependencies resolved */
|
||||
private function _resolveArgs(array $args)
|
||||
private function resolveArgs(array $args)
|
||||
{
|
||||
$resolved = array();
|
||||
foreach ($args as $argDefinition) {
|
||||
switch ($argDefinition['type']) {
|
||||
case 'lookup':
|
||||
$resolved[] = $this->_lookupRecursive($argDefinition['item']);
|
||||
$resolved[] = $this->lookupRecursive($argDefinition['item']);
|
||||
break;
|
||||
case 'value':
|
||||
$resolved[] = $argDefinition['item'];
|
||||
@@ -357,12 +357,12 @@ class Swift_DependencyContainer
|
||||
}
|
||||
|
||||
/** Resolve a single dependency with an collections */
|
||||
private function _lookupRecursive($item)
|
||||
private function lookupRecursive($item)
|
||||
{
|
||||
if (is_array($item)) {
|
||||
$collection = array();
|
||||
foreach ($item as $k => $v) {
|
||||
$collection[$k] = $this->_lookupRecursive($v);
|
||||
$collection[$k] = $this->lookupRecursive($v);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
|
||||
@@ -39,20 +39,6 @@ class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new EmbeddedFile.
|
||||
*
|
||||
* @param string|Swift_OutputByteStream $data
|
||||
* @param string $filename
|
||||
* @param string $contentType
|
||||
*
|
||||
* @return Swift_Mime_EmbeddedFile
|
||||
*/
|
||||
public static function newInstance($data = null, $filename = null, $contentType = null)
|
||||
{
|
||||
return new self($data, $filename, $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new EmbeddedFile from a filesystem path.
|
||||
*
|
||||
@@ -62,8 +48,6 @@ class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
|
||||
*/
|
||||
public static function fromPath($path)
|
||||
{
|
||||
return self::newInstance()->setFile(
|
||||
new Swift_ByteStream_FileByteStream($path)
|
||||
);
|
||||
return (new self())->setFile(new Swift_ByteStream_FileByteStream($path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,21 +22,21 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
*
|
||||
* @var Swift_CharacterStream
|
||||
*/
|
||||
protected $_charStream;
|
||||
protected $charStream;
|
||||
|
||||
/**
|
||||
* A filter used if input should be canonicalized.
|
||||
*
|
||||
* @var Swift_StreamFilter
|
||||
*/
|
||||
protected $_filter;
|
||||
protected $filter;
|
||||
|
||||
/**
|
||||
* Pre-computed QP for HUGE optimization.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $_qpMap = array(
|
||||
protected static $qpMap = array(
|
||||
0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04',
|
||||
5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09',
|
||||
10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E',
|
||||
@@ -91,14 +91,14 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
255 => '=FF',
|
||||
);
|
||||
|
||||
protected static $_safeMapShare = array();
|
||||
protected static $safeMapShare = array();
|
||||
|
||||
/**
|
||||
* A map of non-encoded ascii characters.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_safeMap = array();
|
||||
protected $safeMap = array();
|
||||
|
||||
/**
|
||||
* Creates a new QpEncoder for the given CharacterStream.
|
||||
@@ -108,28 +108,28 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
*/
|
||||
public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null)
|
||||
{
|
||||
$this->_charStream = $charStream;
|
||||
if (!isset(self::$_safeMapShare[$this->getSafeMapShareId()])) {
|
||||
$this->charStream = $charStream;
|
||||
if (!isset(self::$safeMapShare[$this->getSafeMapShareId()])) {
|
||||
$this->initSafeMap();
|
||||
self::$_safeMapShare[$this->getSafeMapShareId()] = $this->_safeMap;
|
||||
self::$safeMapShare[$this->getSafeMapShareId()] = $this->safeMap;
|
||||
} else {
|
||||
$this->_safeMap = self::$_safeMapShare[$this->getSafeMapShareId()];
|
||||
$this->safeMap = self::$safeMapShare[$this->getSafeMapShareId()];
|
||||
}
|
||||
$this->_filter = $filter;
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return array('_charStream', '_filter');
|
||||
return array('charStream', 'filter');
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
if (!isset(self::$_safeMapShare[$this->getSafeMapShareId()])) {
|
||||
if (!isset(self::$safeMapShare[$this->getSafeMapShareId()])) {
|
||||
$this->initSafeMap();
|
||||
self::$_safeMapShare[$this->getSafeMapShareId()] = $this->_safeMap;
|
||||
self::$safeMapShare[$this->getSafeMapShareId()] = $this->safeMap;
|
||||
} else {
|
||||
$this->_safeMap = self::$_safeMapShare[$this->getSafeMapShareId()];
|
||||
$this->safeMap = self::$safeMapShare[$this->getSafeMapShareId()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
{
|
||||
foreach (array_merge(
|
||||
array(0x09, 0x20), range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte) {
|
||||
$this->_safeMap[$byte] = chr($byte);
|
||||
$this->safeMap[$byte] = chr($byte);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,19 +173,19 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
$currentLine = &$lines[$lNo++];
|
||||
$size = $lineLen = 0;
|
||||
|
||||
$this->_charStream->flushContents();
|
||||
$this->_charStream->importString($string);
|
||||
$this->charStream->flushContents();
|
||||
$this->charStream->importString($string);
|
||||
|
||||
// Fetching more than 4 chars at one is slower, as is fetching fewer bytes
|
||||
// Conveniently 4 chars is the UTF-8 safe number since UTF-8 has up to 6
|
||||
// bytes per char and (6 * 4 * 3 = 72 chars per line) * =NN is 3 bytes
|
||||
while (false !== $bytes = $this->_nextSequence()) {
|
||||
while (false !== $bytes = $this->nextSequence()) {
|
||||
// If we're filtering the input
|
||||
if (isset($this->_filter)) {
|
||||
if (isset($this->filter)) {
|
||||
// If we can't filter because we need more bytes
|
||||
while ($this->_filter->shouldBuffer($bytes)) {
|
||||
while ($this->filter->shouldBuffer($bytes)) {
|
||||
// Then collect bytes into the buffer
|
||||
if (false === $moreBytes = $this->_nextSequence(1)) {
|
||||
if (false === $moreBytes = $this->nextSequence(1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -194,10 +194,10 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
}
|
||||
}
|
||||
// And filter them
|
||||
$bytes = $this->_filter->filter($bytes);
|
||||
$bytes = $this->filter->filter($bytes);
|
||||
}
|
||||
|
||||
$enc = $this->_encodeByteSequence($bytes, $size);
|
||||
$enc = $this->encodeByteSequence($bytes, $size);
|
||||
|
||||
$i = strpos($enc, '=0D=0A');
|
||||
$newLineLength = $lineLen + ($i === false ? $size : $i);
|
||||
@@ -219,7 +219,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_standardize(implode("=\r\n", $lines));
|
||||
return $this->standardize(implode("=\r\n", $lines));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,27 +229,27 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
*/
|
||||
public function charsetChanged($charset)
|
||||
{
|
||||
$this->_charStream->setCharacterSet($charset);
|
||||
$this->charStream->setCharacterSet($charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the given byte array into a verbatim QP form.
|
||||
*
|
||||
* @param integer[] $bytes
|
||||
* @param int[] $bytes
|
||||
* @param int $size
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _encodeByteSequence(array $bytes, &$size)
|
||||
protected function encodeByteSequence(array $bytes, &$size)
|
||||
{
|
||||
$ret = '';
|
||||
$size = 0;
|
||||
foreach ($bytes as $b) {
|
||||
if (isset($this->_safeMap[$b])) {
|
||||
$ret .= $this->_safeMap[$b];
|
||||
if (isset($this->safeMap[$b])) {
|
||||
$ret .= $this->safeMap[$b];
|
||||
++$size;
|
||||
} else {
|
||||
$ret .= self::$_qpMap[$b];
|
||||
$ret .= self::$qpMap[$b];
|
||||
$size += 3;
|
||||
}
|
||||
}
|
||||
@@ -262,11 +262,11 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
*
|
||||
* @param int $size number of bytes to read
|
||||
*
|
||||
* @return integer[]
|
||||
* @return int[]
|
||||
*/
|
||||
protected function _nextSequence($size = 4)
|
||||
protected function nextSequence($size = 4)
|
||||
{
|
||||
return $this->_charStream->readBytes($size);
|
||||
return $this->charStream->readBytes($size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,7 +276,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _standardize($string)
|
||||
protected function standardize($string)
|
||||
{
|
||||
$string = str_replace(array("\t=0D=0A", ' =0D=0A', '=0D=0A'),
|
||||
array("=09\r\n", "=20\r\n", "\r\n"), $string
|
||||
@@ -284,7 +284,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
switch ($end = ord(substr($string, -1))) {
|
||||
case 0x09:
|
||||
case 0x20:
|
||||
$string = substr_replace($string, self::$_qpMap[$end], -1);
|
||||
$string = substr_replace($string, self::$qpMap[$end], -1);
|
||||
}
|
||||
|
||||
return $string;
|
||||
@@ -295,6 +295,6 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->_charStream = clone $this->_charStream;
|
||||
$this->charStream = clone $this->charStream;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
|
||||
*
|
||||
* @var Swift_CharacterStream
|
||||
*/
|
||||
private $_charStream;
|
||||
private $charStream;
|
||||
|
||||
/**
|
||||
* Creates a new Rfc2231Encoder using the given character stream instance.
|
||||
@@ -29,7 +29,7 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
|
||||
*/
|
||||
public function __construct(Swift_CharacterStream $charStream)
|
||||
{
|
||||
$this->_charStream = $charStream;
|
||||
$this->charStream = $charStream;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,12 +53,12 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
|
||||
$maxLineLength = 75;
|
||||
}
|
||||
|
||||
$this->_charStream->flushContents();
|
||||
$this->_charStream->importString($string);
|
||||
$this->charStream->flushContents();
|
||||
$this->charStream->importString($string);
|
||||
|
||||
$thisLineLength = $maxLineLength - $firstLineOffset;
|
||||
|
||||
while (false !== $char = $this->_charStream->read(4)) {
|
||||
while (false !== $char = $this->charStream->read(4)) {
|
||||
$encodedChar = rawurlencode($char);
|
||||
if (0 != strlen($currentLine)
|
||||
&& strlen($currentLine.$encodedChar) > $thisLineLength) {
|
||||
@@ -79,7 +79,7 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
|
||||
*/
|
||||
public function charsetChanged($charset)
|
||||
{
|
||||
$this->_charStream->setCharacterSet($charset);
|
||||
$this->charStream->setCharacterSet($charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +87,6 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->_charStream = clone $this->_charStream;
|
||||
$this->charStream = clone $this->charStream;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides quick access to each encoding type.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Encoding
|
||||
{
|
||||
/**
|
||||
* Get the Encoder that provides 7-bit encoding.
|
||||
*
|
||||
* @return Swift_Mime_ContentEncoder
|
||||
*/
|
||||
public static function get7BitEncoding()
|
||||
{
|
||||
return self::_lookup('mime.7bitcontentencoder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Encoder that provides 8-bit encoding.
|
||||
*
|
||||
* @return Swift_Mime_ContentEncoder
|
||||
*/
|
||||
public static function get8BitEncoding()
|
||||
{
|
||||
return self::_lookup('mime.8bitcontentencoder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Encoder that provides Quoted-Printable (QP) encoding.
|
||||
*
|
||||
* @return Swift_Mime_ContentEncoder
|
||||
*/
|
||||
public static function getQpEncoding()
|
||||
{
|
||||
return self::_lookup('mime.qpcontentencoder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Encoder that provides Base64 encoding.
|
||||
*
|
||||
* @return Swift_Mime_ContentEncoder
|
||||
*/
|
||||
public static function getBase64Encoding()
|
||||
{
|
||||
return self::_lookup('mime.base64contentencoder');
|
||||
}
|
||||
|
||||
// -- Private Static Methods
|
||||
|
||||
private static function _lookup($key)
|
||||
{
|
||||
return Swift_DependencyContainer::getInstance()->lookup($key);
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,14 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_command;
|
||||
private $command;
|
||||
|
||||
/**
|
||||
* An array of codes which a successful response will contain.
|
||||
*
|
||||
* @var integer[]
|
||||
* @var int[]
|
||||
*/
|
||||
private $_successCodes = array();
|
||||
private $successCodes = array();
|
||||
|
||||
/**
|
||||
* Create a new CommandEvent for $source with $command.
|
||||
@@ -39,8 +39,8 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject
|
||||
public function __construct(Swift_Transport $source, $command, $successCodes = array())
|
||||
{
|
||||
parent::__construct($source);
|
||||
$this->_command = $command;
|
||||
$this->_successCodes = $successCodes;
|
||||
$this->command = $command;
|
||||
$this->successCodes = $successCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,16 +50,16 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->_command;
|
||||
return $this->command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the numeric response codes which indicate success for this command.
|
||||
*
|
||||
* @return integer[]
|
||||
* @return int[]
|
||||
*/
|
||||
public function getSuccessCodes()
|
||||
{
|
||||
return $this->_successCodes;
|
||||
return $this->successCodes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ interface Swift_Events_EventDispatcher
|
||||
* Create a new SendEvent for $source and $message.
|
||||
*
|
||||
* @param Swift_Transport $source
|
||||
* @param Swift_Mime_Message
|
||||
* @param Swift_Mime_SimpleMessage
|
||||
*
|
||||
* @return Swift_Events_SendEvent
|
||||
*/
|
||||
public function createSendEvent(Swift_Transport $source, Swift_Mime_Message $message);
|
||||
public function createSendEvent(Swift_Transport $source, Swift_Mime_SimpleMessage $message);
|
||||
|
||||
/**
|
||||
* Create a new CommandEvent for $source and $command.
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
class Swift_Events_EventObject implements Swift_Events_Event
|
||||
{
|
||||
/** The source of this Event */
|
||||
private $_source;
|
||||
private $source;
|
||||
|
||||
/** The state of this Event (should it bubble up the stack?) */
|
||||
private $_bubbleCancelled = false;
|
||||
private $bubbleCancelled = false;
|
||||
|
||||
/**
|
||||
* Create a new EventObject originating at $source.
|
||||
@@ -28,7 +28,7 @@ class Swift_Events_EventObject implements Swift_Events_Event
|
||||
*/
|
||||
public function __construct($source)
|
||||
{
|
||||
$this->_source = $source;
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class Swift_Events_EventObject implements Swift_Events_Event
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->_source;
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ class Swift_Events_EventObject implements Swift_Events_Event
|
||||
*/
|
||||
public function cancelBubble($cancel = true)
|
||||
{
|
||||
$this->_bubbleCancelled = $cancel;
|
||||
$this->bubbleCancelled = $cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +58,6 @@ class Swift_Events_EventObject implements Swift_Events_Event
|
||||
*/
|
||||
public function bubbleCancelled()
|
||||
{
|
||||
return $this->_bubbleCancelled;
|
||||
return $this->bubbleCancelled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ class Swift_Events_ResponseEvent extends Swift_Events_EventObject
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_valid;
|
||||
private $valid;
|
||||
|
||||
/**
|
||||
* The response received from the server.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_response;
|
||||
private $response;
|
||||
|
||||
/**
|
||||
* Create a new ResponseEvent for $source and $response.
|
||||
@@ -39,8 +39,8 @@ class Swift_Events_ResponseEvent extends Swift_Events_EventObject
|
||||
public function __construct(Swift_Transport $source, $response, $valid = false)
|
||||
{
|
||||
parent::__construct($source);
|
||||
$this->_response = $response;
|
||||
$this->_valid = $valid;
|
||||
$this->response = $response;
|
||||
$this->valid = $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ class Swift_Events_ResponseEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +60,6 @@ class Swift_Events_ResponseEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
return $this->_valid;
|
||||
return $this->valid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,35 +33,35 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
|
||||
/**
|
||||
* The Message being sent.
|
||||
*
|
||||
* @var Swift_Mime_Message
|
||||
* @var Swift_Mime_SimpleMessage
|
||||
*/
|
||||
private $_message;
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* Any recipients which failed after sending.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_failedRecipients = array();
|
||||
private $failedRecipients = array();
|
||||
|
||||
/**
|
||||
* The overall result as a bitmask from the class constants.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_result;
|
||||
private $result;
|
||||
|
||||
/**
|
||||
* Create a new SendEvent for $source and $message.
|
||||
*
|
||||
* @param Swift_Transport $source
|
||||
* @param Swift_Mime_Message $message
|
||||
* @param Swift_Mime_SimpleMessage $message
|
||||
*/
|
||||
public function __construct(Swift_Transport $source, Swift_Mime_Message $message)
|
||||
public function __construct(Swift_Transport $source, Swift_Mime_SimpleMessage $message)
|
||||
{
|
||||
parent::__construct($source);
|
||||
$this->_message = $message;
|
||||
$this->_result = self::RESULT_PENDING;
|
||||
$this->message = $message;
|
||||
$this->result = self::RESULT_PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,11 +77,11 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
|
||||
/**
|
||||
* Get the Message being sent.
|
||||
*
|
||||
* @return Swift_Mime_Message
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->_message;
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function setFailedRecipients($recipients)
|
||||
{
|
||||
$this->_failedRecipients = $recipients;
|
||||
$this->failedRecipients = $recipients;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function getFailedRecipients()
|
||||
{
|
||||
return $this->_failedRecipients;
|
||||
return $this->failedRecipients;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function setResult($result)
|
||||
{
|
||||
$this->_result = $result;
|
||||
$this->result = $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,6 +124,6 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function getResult()
|
||||
{
|
||||
return $this->_result;
|
||||
return $this->result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@
|
||||
class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
|
||||
{
|
||||
/** A map of event types to their associated listener types */
|
||||
private $_eventMap = array();
|
||||
private $eventMap = array();
|
||||
|
||||
/** Event listeners bound to this dispatcher */
|
||||
private $_listeners = array();
|
||||
private $listeners = array();
|
||||
|
||||
/** Listeners queued to have an Event bubbled up the stack to them */
|
||||
private $_bubbleQueue = array();
|
||||
private $bubbleQueue = array();
|
||||
|
||||
/**
|
||||
* Create a new EventDispatcher.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_eventMap = array(
|
||||
$this->eventMap = array(
|
||||
'Swift_Events_CommandEvent' => 'Swift_Events_CommandListener',
|
||||
'Swift_Events_ResponseEvent' => 'Swift_Events_ResponseListener',
|
||||
'Swift_Events_SendEvent' => 'Swift_Events_SendListener',
|
||||
@@ -42,11 +42,11 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
|
||||
* Create a new SendEvent for $source and $message.
|
||||
*
|
||||
* @param Swift_Transport $source
|
||||
* @param Swift_Mime_Message
|
||||
* @param Swift_Mime_SimpleMessage
|
||||
*
|
||||
* @return Swift_Events_SendEvent
|
||||
*/
|
||||
public function createSendEvent(Swift_Transport $source, Swift_Mime_Message $message)
|
||||
public function createSendEvent(Swift_Transport $source, Swift_Mime_SimpleMessage $message)
|
||||
{
|
||||
return new Swift_Events_SendEvent($source, $message);
|
||||
}
|
||||
@@ -111,13 +111,13 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
|
||||
*/
|
||||
public function bindEventListener(Swift_Events_EventListener $listener)
|
||||
{
|
||||
foreach ($this->_listeners as $l) {
|
||||
foreach ($this->listeners as $l) {
|
||||
// Already loaded
|
||||
if ($l === $listener) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->_listeners[] = $listener;
|
||||
$this->listeners[] = $listener;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,29 +128,29 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
|
||||
*/
|
||||
public function dispatchEvent(Swift_Events_EventObject $evt, $target)
|
||||
{
|
||||
$this->_prepareBubbleQueue($evt);
|
||||
$this->_bubble($evt, $target);
|
||||
$this->prepareBubbleQueue($evt);
|
||||
$this->bubble($evt, $target);
|
||||
}
|
||||
|
||||
/** Queue listeners on a stack ready for $evt to be bubbled up it */
|
||||
private function _prepareBubbleQueue(Swift_Events_EventObject $evt)
|
||||
private function prepareBubbleQueue(Swift_Events_EventObject $evt)
|
||||
{
|
||||
$this->_bubbleQueue = array();
|
||||
$this->bubbleQueue = array();
|
||||
$evtClass = get_class($evt);
|
||||
foreach ($this->_listeners as $listener) {
|
||||
if (array_key_exists($evtClass, $this->_eventMap)
|
||||
&& ($listener instanceof $this->_eventMap[$evtClass])) {
|
||||
$this->_bubbleQueue[] = $listener;
|
||||
foreach ($this->listeners as $listener) {
|
||||
if (array_key_exists($evtClass, $this->eventMap)
|
||||
&& ($listener instanceof $this->eventMap[$evtClass])) {
|
||||
$this->bubbleQueue[] = $listener;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Bubble $evt up the stack calling $target() on each listener */
|
||||
private function _bubble(Swift_Events_EventObject $evt, $target)
|
||||
private function bubble(Swift_Events_EventObject $evt, $target)
|
||||
{
|
||||
if (!$evt->bubbleCancelled() && $listener = array_shift($this->_bubbleQueue)) {
|
||||
if (!$evt->bubbleCancelled() && $listener = array_shift($this->bubbleQueue)) {
|
||||
$listener->$target($evt);
|
||||
$this->_bubble($evt, $target);
|
||||
$this->bubble($evt, $target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject
|
||||
*
|
||||
* @var Swift_TransportException
|
||||
*/
|
||||
private $_exception;
|
||||
private $exception;
|
||||
|
||||
/**
|
||||
* Create a new TransportExceptionEvent for $transport.
|
||||
@@ -31,7 +31,7 @@ class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject
|
||||
public function __construct(Swift_Transport $transport, Swift_TransportException $ex)
|
||||
{
|
||||
parent::__construct($transport);
|
||||
$this->_exception = $ex;
|
||||
$this->exception = $ex;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,6 +41,6 @@ class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject
|
||||
*/
|
||||
public function getException()
|
||||
{
|
||||
return $this->_exception;
|
||||
return $this->exception;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,4 @@ class Swift_FailoverTransport extends Swift_Transport_FailoverTransport
|
||||
|
||||
$this->setTransports($transports);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new FailoverTransport instance.
|
||||
*
|
||||
* @param Swift_Transport[] $transports
|
||||
*
|
||||
* @return Swift_FailoverTransport
|
||||
*/
|
||||
public static function newInstance($transports = array())
|
||||
{
|
||||
return new self($transports);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
{
|
||||
/** The spool directory */
|
||||
private $_path;
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* File WriteRetry Limit.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_retryLimit = 10;
|
||||
private $retryLimit = 10;
|
||||
|
||||
/**
|
||||
* Create a new FileSpool.
|
||||
@@ -35,11 +35,11 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->_path = $path;
|
||||
$this->path = $path;
|
||||
|
||||
if (!file_exists($this->_path)) {
|
||||
if (!mkdir($this->_path, 0777, true)) {
|
||||
throw new Swift_IoException('Unable to create Path ['.$this->_path.']');
|
||||
if (!file_exists($this->path)) {
|
||||
if (!mkdir($this->path, 0777, true)) {
|
||||
throw new Swift_IoException(sprintf('Unable to create path "%s".', $this->path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,25 +77,25 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
*/
|
||||
public function setRetryLimit($limit)
|
||||
{
|
||||
$this->_retryLimit = $limit;
|
||||
$this->retryLimit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues a message.
|
||||
*
|
||||
* @param Swift_Mime_Message $message The message to store
|
||||
* @param Swift_Mime_SimpleMessage $message The message to store
|
||||
*
|
||||
* @throws Swift_IoException
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function queueMessage(Swift_Mime_Message $message)
|
||||
public function queueMessage(Swift_Mime_SimpleMessage $message)
|
||||
{
|
||||
$ser = serialize($message);
|
||||
$fileName = $this->_path.'/'.$this->getRandomString(10);
|
||||
for ($i = 0; $i < $this->_retryLimit; ++$i) {
|
||||
$fileName = $this->path.'/'.$this->getRandomString(10);
|
||||
for ($i = 0; $i < $this->retryLimit; ++$i) {
|
||||
/* We try an exclusive creation of the file. This is an atomic operation, it avoid locking mechanism */
|
||||
$fp = @fopen($fileName.'.message', 'x');
|
||||
$fp = @fopen($fileName.'.message', 'xb');
|
||||
if (false !== $fp) {
|
||||
if (false === fwrite($fp, $ser)) {
|
||||
return false;
|
||||
@@ -108,7 +108,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
}
|
||||
}
|
||||
|
||||
throw new Swift_IoException('Unable to create a file for enqueuing Message');
|
||||
throw new Swift_IoException(sprintf('Unable to create a file for enqueuing Message in "%s".', $this->path));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
*/
|
||||
public function recover($timeout = 900)
|
||||
{
|
||||
foreach (new DirectoryIterator($this->_path) as $file) {
|
||||
foreach (new DirectoryIterator($this->path) as $file) {
|
||||
$file = $file->getRealPath();
|
||||
|
||||
if (substr($file, -16) == '.message.sending') {
|
||||
@@ -140,7 +140,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
*/
|
||||
public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
|
||||
{
|
||||
$directoryIterator = new DirectoryIterator($this->_path);
|
||||
$directoryIterator = new DirectoryIterator($this->path);
|
||||
|
||||
/* Start the transport only if there are queued files to send */
|
||||
if (!$transport->isStarted()) {
|
||||
@@ -200,7 +200,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
|
||||
$ret = '';
|
||||
$strlen = strlen($base);
|
||||
for ($i = 0; $i < $count; ++$i) {
|
||||
$ret .= $base[((int) rand(0, $strlen - 1))];
|
||||
$ret .= $base[random_int(0, $strlen - 1)];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message ID generator.
|
||||
*/
|
||||
interface Swift_IdGenerator
|
||||
{
|
||||
/**
|
||||
* Returns a globally unique string to use for Message-ID or Content-ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateId();
|
||||
}
|
||||
@@ -29,33 +29,15 @@ class Swift_Image extends Swift_EmbeddedFile
|
||||
parent::__construct($data, $filename, $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Image.
|
||||
*
|
||||
* @param string|Swift_OutputByteStream $data
|
||||
* @param string $filename
|
||||
* @param string $contentType
|
||||
*
|
||||
* @return Swift_Image
|
||||
*/
|
||||
public static function newInstance($data = null, $filename = null, $contentType = null)
|
||||
{
|
||||
return new self($data, $filename, $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Image from a filesystem path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return Swift_Image
|
||||
* @return self
|
||||
*/
|
||||
public static function fromPath($path)
|
||||
{
|
||||
$image = self::newInstance()->setFile(
|
||||
new Swift_ByteStream_FileByteStream($path)
|
||||
);
|
||||
|
||||
return $image;
|
||||
return (new self())->setFile(new Swift_ByteStream_FileByteStream($path));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_contents = array();
|
||||
private $contents = array();
|
||||
|
||||
/**
|
||||
* An InputStream for cloning.
|
||||
*
|
||||
* @var Swift_KeyCache_KeyCacheInputStream
|
||||
*/
|
||||
private $_stream;
|
||||
private $stream;
|
||||
|
||||
/**
|
||||
* Create a new ArrayKeyCache with the given $stream for cloning to make
|
||||
@@ -37,7 +37,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function __construct(Swift_KeyCache_KeyCacheInputStream $stream)
|
||||
{
|
||||
$this->_stream = $stream;
|
||||
$this->stream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,16 +52,16 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function setString($nsKey, $itemKey, $string, $mode)
|
||||
{
|
||||
$this->_prepareCache($nsKey);
|
||||
$this->prepareCache($nsKey);
|
||||
switch ($mode) {
|
||||
case self::MODE_WRITE:
|
||||
$this->_contents[$nsKey][$itemKey] = $string;
|
||||
$this->contents[$nsKey][$itemKey] = $string;
|
||||
break;
|
||||
case self::MODE_APPEND:
|
||||
if (!$this->hasKey($nsKey, $itemKey)) {
|
||||
$this->_contents[$nsKey][$itemKey] = '';
|
||||
$this->contents[$nsKey][$itemKey] = '';
|
||||
}
|
||||
$this->_contents[$nsKey][$itemKey] .= $string;
|
||||
$this->contents[$nsKey][$itemKey] .= $string;
|
||||
break;
|
||||
default:
|
||||
throw new Swift_SwiftException(
|
||||
@@ -83,16 +83,16 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode)
|
||||
{
|
||||
$this->_prepareCache($nsKey);
|
||||
$this->prepareCache($nsKey);
|
||||
switch ($mode) {
|
||||
case self::MODE_WRITE:
|
||||
$this->clearKey($nsKey, $itemKey);
|
||||
case self::MODE_APPEND:
|
||||
if (!$this->hasKey($nsKey, $itemKey)) {
|
||||
$this->_contents[$nsKey][$itemKey] = '';
|
||||
$this->contents[$nsKey][$itemKey] = '';
|
||||
}
|
||||
while (false !== $bytes = $os->read(8192)) {
|
||||
$this->_contents[$nsKey][$itemKey] .= $bytes;
|
||||
$this->contents[$nsKey][$itemKey] .= $bytes;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -116,7 +116,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null)
|
||||
{
|
||||
$is = clone $this->_stream;
|
||||
$is = clone $this->stream;
|
||||
$is->setKeyCache($this);
|
||||
$is->setNsKey($nsKey);
|
||||
$is->setItemKey($itemKey);
|
||||
@@ -137,9 +137,9 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function getString($nsKey, $itemKey)
|
||||
{
|
||||
$this->_prepareCache($nsKey);
|
||||
$this->prepareCache($nsKey);
|
||||
if ($this->hasKey($nsKey, $itemKey)) {
|
||||
return $this->_contents[$nsKey][$itemKey];
|
||||
return $this->contents[$nsKey][$itemKey];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is)
|
||||
{
|
||||
$this->_prepareCache($nsKey);
|
||||
$this->prepareCache($nsKey);
|
||||
$is->write($this->getString($nsKey, $itemKey));
|
||||
}
|
||||
|
||||
@@ -166,9 +166,9 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function hasKey($nsKey, $itemKey)
|
||||
{
|
||||
$this->_prepareCache($nsKey);
|
||||
$this->prepareCache($nsKey);
|
||||
|
||||
return array_key_exists($itemKey, $this->_contents[$nsKey]);
|
||||
return array_key_exists($itemKey, $this->contents[$nsKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,7 +179,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function clearKey($nsKey, $itemKey)
|
||||
{
|
||||
unset($this->_contents[$nsKey][$itemKey]);
|
||||
unset($this->contents[$nsKey][$itemKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,7 +189,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*/
|
||||
public function clearAll($nsKey)
|
||||
{
|
||||
unset($this->_contents[$nsKey]);
|
||||
unset($this->contents[$nsKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,10 +197,10 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
|
||||
*
|
||||
* @param string $nsKey
|
||||
*/
|
||||
private function _prepareCache($nsKey)
|
||||
private function prepareCache($nsKey)
|
||||
{
|
||||
if (!array_key_exists($nsKey, $this->_contents)) {
|
||||
$this->_contents[$nsKey] = array();
|
||||
if (!array_key_exists($nsKey, $this->contents)) {
|
||||
$this->contents[$nsKey] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user