Meta Class

The meta class is a simple helper package for generating meta tags. Meta tags are generated by defining the meta tag attributes along with their respective. These attributes are later processed into html meta tags. The following are the available methods of this package.

Class initialization
The Meta class can be initialized as shown below.
  <?php

  use \spoova\mi\core\classes\Meta;

  $meta = new Meta;
                        
We can also instantiate the class by defining the meta charset type as shown below:
  <?php

  use \spoova\mi\core\classes\Meta;

  $meta = new Meta('UTF-8');
                        
Other methods related to this class are discussed below.

Charset
This method is used to set the charset of meta tags. Example is shown below:

Sample: setting charset
  $meta  = new Meta();
  
  $meta->charset('UTF-8');  // set meta character type
                                


Add
The add method is used to add attributes to meta tags. Example is shown below:

Syntax: adding attributes
  $meta->add($name, $content, $type); 
 
    where: 

    $name    : the name, property or http-equiv attribute value of meta a tag.
    $content : the content attribute of meta tags 
    $type    : the type of meta tag. Options - [name|property|http-equiv]
                default type is name.

                                    
Example: adding attributes
  $meta->add('viewport', 'width=device-width, initial-scale=1.0');
  
  $meta->add('robots', 'noindex, nofollow');
  
  $meta->add('description','150 words');
  
  $meta->add('og:type', 'game.achievement', 'property');
  
  $meta->add('Pragma', 'no-cache', 'http-equiv');
                                    
Examples above respectfully translates:
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  
  <meta name="robots" content="noindex, nofollow"/>
  
  <meta name="description" content="150 words"/>
  
  <meta property="og:type" content="game.achievement"/>
  
  <meta http-equiv="Pragma" content="no-cache"/>
    

name
The name method is a shorthand for the meta tags with the attribute of property. Example is shown below:

Syntax: adding property tags
  $meta->name(name, content); 
   
    where: 

    name : the name attribute value of meta tag
    content  : the content attribute value of meta tag
  
                                    
Example: adding named meta tags
  $meta->name('description', '150 words');  
                                    
Example above translates as:
  <meta name="description" content="150 words"/>
                                    

Prop
The prop method is a shorthand for the meta tags with the attribute of property. Example is shown below:

Syntax: adding property tags
  $meta->prop(property, content); 
 
    where: 

    property : the property attribute value of meta tag
    content  : the content attribute value of meta tag

                                    
Example: adding property meta tags
  $meta->prop('og:type', 'game.achievement');  
                                    
Example above translates as:
  <meta property="og:type" content="game.achievement"/>
                                    

http-equiv
The equiv method is a shorthand for the meta tags with the attribute of http-equiv. Example is shown below:

Syntax: adding http-equiv to meta tags
  $meta->equiv(http-equiv, content); 
     
        where: 

        http-equiv : the http-equiv attribute value of meta tag
        content  : the content attribute value of meta tag
    
                                    
Example: adding http-equiv meta tags
  $meta->equiv('Pragma', 'no-cache',);
                                    
Example above translates as
   <meta http-equiv="Pragma" content="no-cache"/>
                                    

refresh
The refresh method is a shorthand for the meta tags with the attribute of http-equiv="refresh". Example is shown below:

Syntax: adding http-equiv to meta tags
  $meta->refresh(time); 
     
        where: 

        time : time in seconds
    
                                    
Example: adding refresh to meta tags
  $meta->refresh(30);
                                    
Example above translates as:
  <meta http-equiv="refresh" content="30"/>
                                    

og
The og method is a shorthand for the meta tags with the attribute of property="og:". Example is shown below:

Syntax: adding og to meta tags
  $meta->og(type, content); 
     
        where: 

        type : og type.
        content : content atttribute of og meta tags.
    
                                    
Example: adding og property to meta tags
  $meta->og('type', 'game.achievement');  
                                    
Example above translates as:
  <meta property="og:type" content="game.achievement"/>
                                    

drop
The drop() method removes all stored meta definitions from storage list.

Sample: clearing definitions
  $meta->add('description', '150 words'); 

  $meta->drop(); // clear previous descriptions 
                                    

export
The export() method displays all stored meta definitions from storage list on each line.

Sample: display all stored meta tags
  $meta->export(); // displays each predefined meta tags in a listed order 
                                    

dump
The dump() method returns all stored meta tags. However, when a boolean argument of true is supplied, it prints out all stored meta tags.

Sample: clearing definitions
  $meta->add('description', '150 words'); 

  vdump($meta->dump()); // return predefined meta tags 
  
  $meta->dump(true); // prints predefined meta tags 
                                    

sample
The sample() method returns an array of meta tag samples. This data was compiled from across different source on the internet.

Sample: get samples of meta tags
  vdump( $meta->sample() ); // outputs array of meta tag sample attributes