public function fromArray ($attributes, $removeClass = FALSE, $validate = TRUE, $required = array (), $valid = array ())
	{
		
		// Remove class prefix
		
		if ($removeClass)
		{
			
			// Set attributes to set

			$arr	= array ();

			// Get class name

			$class	= strtolower ($this->getClass ());

			// Loop through attributes and add any that exist with the class name

			foreach (array_keys (static::$attributes) as $name)
			{

				if (isset ($attributes[$class . '_' . strtolower ($name)]))
				{
					$arr[$name]	= $attributes[$class . '_' . $name];
				}

			}
			
			// Set attributes
			
			$attributes	= $arr;
			
		}
		
		// If we have an array of valid attributes to set
		// Remove any that arent valid
		
		if ($valid)
		{
			
			foreach (array_keys ($attributes) as $name)
			{
				
				if (!in_array ($name, $valid, TRUE))
				{
					unset ($attributes[$name]);
				}
				
			}
			
		}
		
		// Set each attribute
		
		try
		{
			
			foreach ($attributes as $name => $val)
			{
				
				if ($this->attributeExists ($name) && $this->attributeSet ($name))
				{
					$this->set ($name, $val, $validate);
				}
				
				if (($key = array_search ($name, $required, TRUE)) !== FALSE)
				{
					unset ($required[$key]);
				}
				
			}
			
			// Error if there are required fields that have not been set
			
			if (count ($required) > 0)
			{
				
				foreach ($required as $name)
				{
					
					if ($this->attributeExists ($name) && isset (static::$attributes[$name]['name']))
					{
						$name	= static::$attributes[$name]['name'];
					}
					
					$word	= in_array (strtoupper ($name[0]), array ('A', 'E', 'I', 'O'))? 'an' : 'a';
					
					new Message ('error', 'You have not entered ' . $word . ' ' . ucwords ($name));
					
				}
				
			}
			
		}
		
		// Set errors as framework messages
		
		catch (Resource\Parser\Exception $e)
		{
			new Message ('error', $e->getMessage ());
		}
		
	}
public function fromArray ($attributes, $removeClass = FALSE, $validate = TRUE, $required = array (), $valid = array ())
	{
		
		// Remove class prefix
		
		if ($removeClass)
		{
			
			// Set attributes to set

			$arr	= array ();

			// Get class name

			$class	= strtolower ($this->getClass ());

			// Loop through attributes and add any that exist with the class name

			foreach (array_keys (static::$attributes) as $name)
			{

				if (isset ($attributes[$class . '_' . strtolower ($name)]))
				{
					$arr[$name]	= $attributes[$class . '_' . $name];
				}

			}
			
			// Set attributes
			
			$attributes	= $arr;
			
		}
		
		// If we have an array of valid attributes to set
		// Remove any that arent valid
		
		if ($valid)
		{
			
			foreach (array_keys ($attributes) as $name)
			{
				
				if (!in_array ($name, $valid, TRUE))
				{
					unset ($attributes[$name]);
				}
				
			}
			
		}
		
		// Set each attribute
		
		try
		{
			
			foreach ($attributes as $name => $val)
			{
				
				if ($this->attributeExists ($name) && $this->attributeSet ($name))
				{
					$this->set ($name, $val, $validate);
				}
				
				if (($key = array_search ($name, $required, TRUE)) !== FALSE)
				{
					unset ($required[$key]);
				}
				
			}
			
			// Error if there are required fields that have not been set
			
			if (count ($required) > 0)
			{
				
				foreach ($required as $name)
				{
					
					if ($this->attributeExists ($name) && isset (static::$attributes[$name]['name']))
					{
						$name	= static::$attributes[$name]['name'];
					}
					
					$word	= in_array (strtoupper ($name[0]), array ('A', 'E', 'I', 'O'))? 'an' : 'a';
					
					new Message ('error', 'You have not entered ' . $word . ' ' . ucwords ($name));
					
				}
				
			}
			
		}
		
		// Set errors as framework messages
		
		catch (Resource\Parser\Exception $e)
		{
			new Message ('error', $e->getMessage ());
		}
		
	}
public function fromArray ( $ attributes , $ removeClass = FALSE , $ validate = TRUE , $ required = array ( ) , $ valid = array ( ) ) { // Remove class prefix if ( $ removeClass ) { // Set attributes to set $ arr = array ( ) ; // Get class name $ class = strtolower ( $ this -> getClass ( ) ) ; // Loop through attributes and add any that exist with the class name foreach ( array_keys ( static :: $ attributes ) as $ name ) { if ( isset ( $ attributes [ $ class . '_' . strtolower ( $ name ) ] ) ) { $ arr [ $ name ] = $ attributes [ $ class . '_' . $ name ] ; } } // Set attributes $ attributes = $ arr ; } // If we have an array of valid attributes to set // Remove any that arent valid if ( $ valid ) { foreach ( array_keys ( $ attributes ) as $ name ) { if ( ! in_array ( $ name , $ valid , TRUE ) ) { unset ( $ attributes [ $ name ] ) ; } } } // Set each attribute try { foreach ( $ attributes as $ name => $ val ) { if ( $ this -> attributeExists ( $ name ) && $ this -> attributeSet ( $ name ) ) { $ this -> set ( $ name , $ val , $ validate ) ; } if ( ( $ key = array_search ( $ name , $ required , TRUE ) ) !== FALSE ) { unset ( $ required [ $ key ] ) ; } } // Error if there are required fields that have not been set if ( count ( $ required ) > 0 ) { foreach ( $ required as $ name ) { if ( $ this -> attributeExists ( $ name ) && isset ( static :: $ attributes [ $ name ] [ 'name' ] ) ) { $ name = static :: $ attributes [ $ name ] [ 'name' ] ; } $ word = in_array ( strtoupper ( $ name [ 0 ] ) , array ( 'A' , 'E' , 'I' , 'O' ) ) ? 'an' : 'a' ; new Message ( 'error' , 'You have not entered ' . $ word . ' ' . ucwords ( $ name ) ) ; } } } // Set errors as framework messages catch ( Resource \ Parser \ Exception $ e ) { new Message ( 'error' , $ e -> getMessage ( ) ) ; } }
Populate object attributes from an array
@param array $attributes Attributes array
@param boolean $removeClass Remove class prefix from the attribute name
@param boolean $validate Validate attributes during set
@param array $required Required attributes
@param array $valid Valid attributes to set
@return void
Populate object attributes from an array