PHP Classes

File: examples.php

Recommend this page to a friend!
  Classes of Till Wehowski   Flag Mask   examples.php   Download  
File: examples.php
Role: Example script
Content type: text/plain
Description: Snippets of example implementations
Class: Flag Mask
Manage groups of bit values in bitmasks
Author: By
Last change:
Date: 10 years ago
Size: 6,165 bytes
 

Contents

Class file image Download
<?php

 $pi
= new stdclass;
 
$pi->header = array();
 
$pi->header['DOCTYPE'] = '.wwim|webdof interface mapping';
 
$pi->header['title'] = 'webdof.Webfan.Setup';



 
//Base Class Interfaces
 
$pi->classes = array();
 
$pi->classes[] = '\webdof\Webfan\Setup';


 
//Plugin Interfaces
 
$pi->interfaces = array();



 
$labels = array();

 
$labels[] = array('supported', 'Produkt verf&uuml;gbar', FALSE);
 
$labels[] = array('required', 'Produkt obligatorisch', FALSE);
 
$labels[] = array('recommended', 'Produkt empfohlen', FALSE);
 
$labels[] = array('incompatible', 'Produkt inkompatibel', FALSE);
 
$labels[] = array('premium', 'kostenpflichtig', FALSE);

 
$labels[] = array('boot', 'Initial Boot Method', FALSE);

 
$labels[] = array('on_boot', 'Load by initial method', FALSE);
 
$labels[] = array('status_8', 'Status Flag 8', FALSE);


 
$status_boot = new \webdof\Serialize\Bit\FlagMask();
 
$status_boot->setLabels($labels);
 
$status_boot->set('supported', TRUE);
 
$status_boot->set('required', TRUE);
 
$status_boot->set('boot', TRUE);
 
$status_boot->set('on_boot', FALSE);


 
$status_required_and_compatible = new \webdof\Serialize\Bit\FlagMask();
 
$status_required_and_compatible->setLabels($labels);
// $status_required_and_compatible->set('incompatible', FALSE);
 
$status_required_and_compatible->set('supported', TRUE);
 
$status_required_and_compatible->set('required', TRUE);
 
$status_required_and_compatible->set('on_boot', TRUE);


 
$status_icompatible_and_unavailable = new \webdof\Serialize\Bit\FlagMask();
 
$status_icompatible_and_unavailable->setLabels($labels);
 
$status_icompatible_and_unavailable->set('supported', FALSE);
 
$status_icompatible_and_unavailable->set('incompatible', TRUE);
 
$status_icompatible_and_unavailable->set('on_boot', FALSE);

/*
 $aPlugin = new stdclass;
 $aPlugin->method = '__MOCK__';
 $aPlugin->dir = '__MOCK__';
 $aPlugin->file = '__MOCK__.php';
 $aPlugin->status = $status_icompatible_and_unavailable->save();
 $pi->interfaces[] = $aPlugin;


 $aPlugin = new stdclass;
 $aPlugin->method = '__REMOTESUPPORT__';
 $aPlugin->dir = '__REMOTESUPPORT__';
 $aPlugin->file = '__REMOTESUPPORT__.php';
 $aPlugin->status = $status_icompatible_and_unavailable->save();
 $pi->interfaces[] = $aPlugin;
*/


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'wpSetupLoadPlugins';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'wpSetupLoadPlugins.php';
 
$aPlugin->status = $status_boot->save();
 
$pi->interfaces[] = $aPlugin;


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'license_credits';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'license_credits.php';
 
$aPlugin->status = $status_required_and_compatible->save();
 
$pi->interfaces[] = $aPlugin;


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'table_credits';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'table_credits.php';
 
$aPlugin->status = $status_required_and_compatible->save();
 
$pi->interfaces[] = $aPlugin;


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'wpDetect';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'wpDetect.php';
 
$aPlugin->status = $status_required_and_compatible->save();
 
$pi->interfaces[] = $aPlugin;


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'wpUrlMapping';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'wpUrlMapping.php';
 
$aPlugin->status = $status_required_and_compatible->save();
 
$pi->interfaces[] = $aPlugin;


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'wpHomeUrl';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'wpHomeUrl.php';
 
$aPlugin->status = $status_required_and_compatible->save();
 
$pi->interfaces[] = $aPlugin;


 
$aPlugin = new stdclass;
 
$aPlugin->method = 'wpHtmlHeader';
 
$aPlugin->dir = 'Setup';
 
$aPlugin->file = 'wpHtmlHeader.php';
 
$aPlugin->status = $status_required_and_compatible->save();
 
$pi->interfaces[] = $aPlugin;



 
// Set status of second plugin to paid:
 
$status_paid_content = new \webdof\Serialize\Bit\FlagMask();
 
$status_paid_content->setLabels($labels);
 
$status_paid_content->set('required', FALSE);
 
$status_paid_content->set('supported', TRUE);
 
$status_paid_content->set('premium', TRUE);

 
$pi->interfaces[1]->status = $status_paid_content->save();
// echo '$pi->interfaces[1]<pre>'.print_r($pi->interfaces[1], TRUE).'</pre><br />';
// echo '$status_paid_content<pre>'.print_r($status_paid_content, TRUE).'</pre><br />';


   //Set all flags of mock to true:
  
$status_test = new \webdof\Serialize\Bit\FlagMask();
  
$status_test->setLabels($labels);
  
$status_test->load( $status_test->max() );
  
$pi->interfaces[0]->status = $status_test->save();
// echo 'Set all flags of mock to true: $pi->interfaces[0]<pre>'.print_r($pi->interfaces[0], TRUE).'</pre><br />';



   //check if a plugin available
    //init object
  
    
$k = mt_rand(0, count($pi->interfaces) - 1 );
    
$status = new \webdof\Serialize\Bit\FlagMask();
    
$status->setLabels($labels);
   
//load value from plugin $k
  
$status->load( $pi->interfaces[$k]->status );
  
$supported = $status->is("supported");
   echo
'check if a plugin available $pi->interfaces['.$k.'] $status->is("supported")<pre>'
                
.print_r($supported , TRUE).'</pre><br />';


  
$status_test = new \webdof\Serialize\Bit\FlagMask();
  
$status_test->setLabels($labels);
  
$status_test->load( 0 );
  
$pi->interfaces[0]->status = 0;
// echo 'Set all flags of mock to false: $pi->interfaces[0]<pre>'.print_r($status_test, TRUE).'</pre><br />';
 


###########

              
$status = new \webdof\Serialize\Bit\FlagMask();
               
$status->setLabels($labels);
               
$status->load($p->status );

               
$p->flag_sets = $status->getLabels();

                if(
$status->is('supported') != 1)continue;
                if(
$status->is('required') === 1)$force = TRUE;
                 
//recommended
               
if( $status->is('incompatible') === 1)continue;
                
//premium
               
if( $status->is('boot') === 1)continue; // self method
               
if( $status->is('on_boot') === 0)continue;