concrete5  5.6.3
 All Data Structures Namespaces Files Functions Variables Pages
File.php
Go to the documentation of this file.
1 <?php
26 require_once 'Zend/Mail/Transport/Abstract.php';
27 
28 
41 {
47  protected $_path;
48 
54  protected $_callback;
55 
62  public function __construct($options = null)
63  {
64  if ($options instanceof Zend_Config) {
65  $options = $options->toArray();
66  } elseif (!is_array($options)) {
67  $options = array();
68  }
69 
70  // Making sure we have some defaults to work with
71  if (!isset($options['path'])) {
72  $options['path'] = sys_get_temp_dir();
73  }
74  if (!isset($options['callback'])) {
75  $options['callback'] = array($this, 'defaultCallback');
76  }
77 
78  $this->setOptions($options);
79  }
80 
87  public function setOptions(array $options)
88  {
89  if (isset($options['path'])&& is_dir($options['path'])) {
90  $this->_path = $options['path'];
91  }
92  if (isset($options['callback']) && is_callable($options['callback'])) {
93  $this->_callback = $options['callback'];
94  }
95  }
96 
104  protected function _sendMail()
105  {
106  $file = $this->_path . DIRECTORY_SEPARATOR . call_user_func($this->_callback, $this);
107 
108  if (!is_writable(dirname($file))) {
109  require_once 'Zend/Mail/Transport/Exception.php';
110  throw new Zend_Mail_Transport_Exception(sprintf(
111  'Target directory "%s" does not exist or is not writable',
112  dirname($file)
113  ));
114  }
115 
116  $email = $this->header . $this->EOL . $this->body;
117 
118  if (!file_put_contents($file, $email)) {
119  require_once 'Zend/Mail/Transport/Exception.php';
120  throw new Zend_Mail_Transport_Exception('Unable to send mail');
121  }
122  }
123 
130  public function defaultCallback($transport)
131  {
132  return 'ZendMail_' . $_SERVER['REQUEST_TIME'] . '_' . mt_rand() . '.tmp';
133  }
134 }