Container
[ class tree: Container ] [ index: Container ] [ all elements ]

Source for file Input.php

Documentation is available at Input.php

  1. <?php
  2. /**
  3.  * Mai_Container_Input
  4.  * 
  5.  * Copyright (C) 2009  Mai (Me Artificial Intelligence)
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation, either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  * 
  20.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  21.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  22.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  23.  * @link http://www.launchpad.net/mai
  24.  * 
  25.  * @category Mai
  26.  * @package Container
  27.  * @subpackage Input
  28.  * 
  29.  */
  30.  
  31. /** Load required file */
  32. {
  33.     require_once 'Mai/Container/Input/Interface.php';
  34. }
  35.  
  36. /**
  37.  * Mai_Container_Input is a container for input.
  38.  * Input types currently supported:
  39.  * - Sentences
  40.  * 
  41.  * @author Wouter Bulten (wouterbulten@mai-ai.org)
  42.  * @copyright Copyright (C) 2009  Mai (Me Artificial Intelligence)
  43.  * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
  44.  * @link http://www.launchpad.net/mai
  45.  * 
  46.  * @category Mai
  47.  * @package Container
  48.  * @subpackage Input
  49.  *
  50.  */
  51. class Mai_Container_Input implements Mai_Container_Input_Interface
  52. {
  53.     /**
  54.      * @var int Type of input.
  55.      */
  56.     private $_inputType = 0;
  57.     
  58.     /**
  59.      * @var array Storage for sentences.
  60.      */
  61.     private $_sentences = array();
  62.     
  63.     /**
  64.      * Set the input type of this container.
  65.      * @param int $type 
  66.      */
  67.     public function setType($type)
  68.     {
  69.         //Only normal input (sentences) is currently supported
  70.         if($type !== Mai::MSG_TYPE_NORMAL)
  71.         {
  72.             trigger_error('Type is not valid or not supported.'E_USER_WARNING);
  73.         }
  74.         
  75.         $this->_inputType = $type;
  76.     }
  77.     
  78.     /**
  79.      * Get the type of this container.
  80.      * @return int 
  81.      */
  82.     public function getType()
  83.     {
  84.         return $this->_inputType;
  85.     }
  86.     
  87.     /**
  88.      * Insert a word in the storage.
  89.      * @param Mai_Container_Sentence The sentence to store.
  90.      * @param $location The location (key) where to store.
  91.      */
  92.     public function insertSentence(Mai_Container_Sentence $sentence$location null)
  93.     {
  94.         if(!isset($location|| !is_numeric($location))
  95.         {
  96.             $this->_sentences[$sentence;
  97.         }
  98.         else
  99.         {
  100.             $this->_sentences[$location$sentence;
  101.         }
  102.     }
  103.     
  104.     /**
  105.      * Return a sentence from storage.
  106.      * @param Int $location The location (key) of storage.
  107.      * @param Bool $showError Set to false to return false if a sentence does not excist.
  108.      * @return Mai_Container_Sentence 
  109.      */
  110.     public function getSentence($location$showError true)
  111.     {
  112.         if(!isset($location|| !is_numeric($location))
  113.         {
  114.             trigger_error('Location not set.'E_USER_ERROR);
  115.         }
  116.         
  117.         if(isset($this->_sentences[$location]&& $showError === true)
  118.         {
  119.             trigger_error('Sentences does not excist for location.'E_USER_NOTICE);
  120.         }
  121.         else
  122.         {
  123.             return false;
  124.         }
  125.         
  126.         return $this->_sentences[$location];
  127.     }
  128.     
  129.     /**
  130.      * Return all sentences
  131.      * @return array 
  132.      */
  133.     public function getAll()
  134.     {
  135.         return $this->_sentences;
  136.     }
  137.     
  138.     /**
  139.      * Function to implement the IteratorAggregate interface.
  140.      * @return ArrayIterator 
  141.      */
  142.     public function getIterator()
  143.     {
  144.         return new ArrayIterator($this->_sentences);
  145.     }
  146. }

Documentation generated on Mon, 27 Jul 2009 19:55:06 +0200 by phpDocumentor 1.4.1