Apache Zeta Components Manual :: File Source for walk_context.php

Source for file walk_context.php

Documentation is available at walk_context.php

  1. <?php
  2. /**
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  *
  21.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22.  * @version //autogentag//
  23.  * @filesource
  24.  * @package Mail
  25.  */
  26.  
  27. /**
  28.  * Use this class to create a context to be passed to the walkParts() method from ezcMail.
  29.  *
  30.  * Example:
  31.  * <code>
  32.  * class App
  33.  * {
  34.  *     public static function saveMailPart( $context, $mailPart )
  35.  *     {
  36.  *         // code to save the $mailPart object to disk
  37.  *     }
  38.  * }
  39.  *
  40.  * // use the saveMailPart() function as a callback in walkParts()
  41.  * // where $mail is an ezcMail object.
  42.  * $context = new ezcMailPartWalkContext( array( 'App', 'saveMailPart' ) );
  43.  * $context->includeDigests = true; // if you want to go through the digests in the mail
  44.  * $mail->walkParts( $context, $mail );
  45.  * </code>
  46.  *
  47.  * @property array(string) $filter 
  48.  *            Used to restrict processing only to the specified mail part names.
  49.  *            If empty or null, then ezcMailText, ezcMailFile and ezcMailRfc822Digest
  50.  *            parts are processed. Usage e.g.: array( 'ezcMailFile' )
  51.  * @property callback $callbackFunction 
  52.  *            Name of a function or array( 'class_name', 'function_name' )
  53.  * @property bool $includeDigests 
  54.  *            If true then then ezcMailRfc822Digest parts are not processed by
  55.  *            the callback function, instead the mail parts inside the digests will
  56.  *            be available for processing.
  57.  * @property int $level 
  58.  *            The current level in the mail part walk (0 = first level).
  59.  *
  60.  * @package Mail
  61.  * @version //autogentag//
  62.  */
  63. {
  64.     /**
  65.      * An array of mail parts (retrieved recursively from a mail object).
  66.      *
  67.      * @var array(ezcMailPart) 
  68.      */
  69.     protected $parts = array();
  70.  
  71.     /**
  72.      * Holds the properties of this class.
  73.      *
  74.      * @var array(string=>mixed) 
  75.      */
  76.     private $properties array();
  77.  
  78.     /**
  79.      * Constructs a new ezcMailPartWalkContext object.
  80.      *
  81.      * The parameter $callbackFunction must be a function name as string or as
  82.      * array( 'class_name', 'function_name' ).
  83.      *
  84.      * @param callback $callbackFunction 
  85.      */
  86.     public function __construct$callbackFunction )
  87.     {
  88.         $this->callbackFunction $callbackFunction;
  89.         $this->level 0;
  90.         $this->filter array();
  91.         $this->includeDigests false;
  92.     }
  93.  
  94.     /**
  95.      * Sets the property $name to $value.
  96.      *
  97.      * @throws ezcBasePropertyNotFoundException
  98.      *          if the property $name does not exist
  99.      * @throws ezcBaseValueException
  100.      *          if $value is not appropiate for property $name
  101.      * @param string $name 
  102.      * @param mixed $value 
  103.      * @ignore
  104.      */
  105.     public function __set$name$value )
  106.     {
  107.         switch $name )
  108.         {
  109.             case 'level':
  110.                 if !is_numeric$value|| $value )
  111.                 {
  112.                     throw new ezcBaseValueException$name$value'int >= 0' );
  113.                 }
  114.                 $this->properties[$name= (int) $value;
  115.                 break;
  116.  
  117.             case 'includeDigests':
  118.                 if !is_bool$value ) )
  119.                 {
  120.                     throw new ezcBaseValueException$name$value'bool' );
  121.                 }
  122.                 $this->properties[$name= (bool) $value;
  123.                 break;
  124.  
  125.             case 'filter':
  126.                 $this->properties[$name$value;
  127.                 break;
  128.  
  129.             case 'callbackFunction':
  130.                 $this->properties[$name$value;
  131.                 break;
  132.  
  133.             default:
  134.                 throw new ezcBasePropertyNotFoundException$name );
  135.         }
  136.     }
  137.  
  138.     /**
  139.      * Returns the value of the property $name.
  140.      *
  141.      * @throws ezcBasePropertyNotFoundException
  142.      *          if the property $name does not exist
  143.      * @param string $name 
  144.      * @return mixed 
  145.      * @ignore
  146.      */
  147.     public function __get$name )
  148.     {
  149.         switch $name )
  150.         {
  151.             case 'level':
  152.             case 'filter':
  153.             case 'callbackFunction':
  154.             case 'includeDigests':
  155.                 return $this->properties[$name];
  156.  
  157.             default:
  158.                 throw new ezcBasePropertyNotFoundException$name );
  159.         }
  160.     }
  161.  
  162.     /**
  163.      * Returns true if the property $name is set, otherwise false.
  164.      *
  165.      * @param string $name 
  166.      * @return bool 
  167.      * @ignore
  168.      */
  169.     public function __isset$name )
  170.     {
  171.         switch $name )
  172.         {
  173.             case 'level':
  174.             case 'filter':
  175.             case 'callbackFunction':
  176.             case 'includeDigests':
  177.                 return isset$this->properties[$name);
  178.  
  179.             default:
  180.                 return false;
  181.         }
  182.     }
  183.  
  184.     /**
  185.      * Appends a part to the list of mail parts.
  186.      *
  187.      * @param ezcMailPart $part 
  188.      */
  189.     public function appendPartezcMailPart $part )
  190.     {
  191.         $this->parts[$part;
  192.     }
  193.  
  194.     /**
  195.      * Returns the mail parts.
  196.      *
  197.      * @return array(ezcMailPart) 
  198.      */
  199.     public function getParts()
  200.     {
  201.         return $this->parts;
  202.     }
  203. }
  204. ?>
Documentation generated by phpDocumentor 1.4.3