Overview

Namespaces

  • webfilesframework
    • codegeneration
      • general
      • php
    • core
      • datastore
        • functions
          • filter
          • sorting
        • types
          • database
            • resultHandler
          • directory
          • googlecalendar
          • mail
          • remote
      • datasystem
        • database
        • file
          • format
            • media
              • image
                • handler
          • system
            • dropbox
      • datatypes
        • time
      • time
    • io
      • form
        • formItem
        • validation
        • webfile
      • request

Classes

  • webfilesframework\codegeneration\general\MAbstractClass
  • webfilesframework\codegeneration\general\MAbstractClassAttribute
  • webfilesframework\codegeneration\general\MAbstractClassMethod
  • webfilesframework\codegeneration\general\MAbstractClassMethodParameter
  • webfilesframework\codegeneration\general\MAbstractCodeItem
  • webfilesframework\codegeneration\MCodeItemFactory
  • webfilesframework\codegeneration\MProgrammingLanguage
  • webfilesframework\codegeneration\MWebfileClassGeneration
  • webfilesframework\codegeneration\php\MPhpClassAttribute
  • webfilesframework\codegeneration\php\MPhpClassMethod
  • webfilesframework\codegeneration\php\MPhpClassMethodParameter
  • webfilesframework\codegeneration\php\MPhpWebfileClass
  • webfilesframework\core\datastore\functions\filter\MSubstringFiltering
  • webfilesframework\core\datastore\functions\sorting\MAscendingSorting
  • webfilesframework\core\datastore\functions\sorting\MDescendingSorting
  • webfilesframework\core\datastore\MAbstractCachableDatastore
  • webfilesframework\core\datastore\MAbstractDatastore
  • webfilesframework\core\datastore\MCombinedDatastore
  • webfilesframework\core\datastore\MDatastoreFactory
  • webfilesframework\core\datastore\MDatastoreTransfer
  • webfilesframework\core\datastore\types\database\MDatabaseDatastore
  • webfilesframework\core\datastore\types\database\MSampleWebfile
  • webfilesframework\core\datastore\types\database\resultHandler\MMysqlResultHandler
  • webfilesframework\core\datastore\types\directory\MDirectoryDatastore
  • webfilesframework\core\datastore\types\directory\MDirectoryDatastoreMetainformation
  • webfilesframework\core\datastore\types\directory\MDirectoryDatastoreWebfile
  • webfilesframework\core\datastore\types\googlecalendar\MEvent
  • webfilesframework\core\datastore\types\googlecalendar\MGoogleCalendarDatastore
  • webfilesframework\core\datastore\types\mail\MImapDatastore
  • webfilesframework\core\datastore\types\mail\MMail
  • webfilesframework\core\datastore\types\mail\MMailAccount
  • webfilesframework\core\datastore\types\remote\MRemoteDatastore
  • webfilesframework\core\datastore\types\remote\MRemoteDatastoreEndpoint
  • webfilesframework\core\datasystem\database\MDatabaseConnection
  • webfilesframework\core\datasystem\database\MDatabaseDatatypes
  • webfilesframework\core\datasystem\database\MDatabaseTable
  • webfilesframework\core\datasystem\database\MDatabaseTableColumn
  • webfilesframework\core\datasystem\file\format\media\image\handler\MAbstractImageLibraryHandler
  • webfilesframework\core\datasystem\file\format\media\image\handler\MGdHandler
  • webfilesframework\core\datasystem\file\format\media\image\handler\MImageMagickHandler
  • webfilesframework\core\datasystem\file\format\media\image\MImage
  • webfilesframework\core\datasystem\file\format\media\image\MQrCodeImage
  • webfilesframework\core\datasystem\file\format\media\MYoutubeVideo
  • webfilesframework\core\datasystem\file\format\MWebfile
  • webfilesframework\core\datasystem\file\format\MWebfileStream
  • webfilesframework\core\datasystem\file\system\dropbox\MDropboxAccount
  • webfilesframework\core\datasystem\file\system\dropbox\MDropboxDirectory
  • webfilesframework\core\datasystem\file\system\dropbox\MDropboxFile
  • webfilesframework\core\datasystem\file\system\MDirectory
  • webfilesframework\core\datasystem\file\system\MFile
  • webfilesframework\core\datatypes\time\MTimestampHelper
  • webfilesframework\core\time\MTimespan
  • webfilesframework\core\time\MWeekday
  • webfilesframework\io\form\formItem\MAbstractFormItem
  • webfilesframework\io\form\formItem\MCheckboxesFormItem
  • webfilesframework\io\form\formItem\MDateFormItem
  • webfilesframework\io\form\formItem\MDateTimeFormItem
  • webfilesframework\io\form\formItem\MDropdownMenueFormItem
  • webfilesframework\io\form\formItem\MHiddenFormItem
  • webfilesframework\io\form\formItem\MHtmlTextareaFormItem
  • webfilesframework\io\form\formItem\MPasswordFormItem
  • webfilesframework\io\form\formItem\MTextareaFormItem
  • webfilesframework\io\form\formItem\MTextfieldFormItem
  • webfilesframework\io\form\formItem\MTimeFormItem
  • webfilesframework\io\form\formItem\MWeekdayFormItem
  • webfilesframework\io\form\MForm
  • webfilesframework\io\form\MFormItemFactory
  • webfilesframework\io\form\validation\MValidator
  • webfilesframework\io\form\webfile\MWebfileFormHandler
  • webfilesframework\io\form\webfile\MWebfileFormVisualizer
  • webfilesframework\io\request\MAbstractHttpRequest
  • webfilesframework\io\request\MGetHttpRequest
  • webfilesframework\io\request\MPostHttpRequest
  • webfilesframework\io\request\MUrl

Interfaces

  • webfilesframework\core\datastore\functions\MIDatastoreFunction
  • webfilesframework\core\datastore\MISingleDatasourceDatastore
  • webfilesframework\core\datastore\types\database\resultHandler\MIResultHandler
  • webfilesframework\core\datastore\types\googlecalendar\MISecretStore

Exceptions

  • webfilesframework\core\datastore\MDatastoreException
  • webfilesframework\core\datastore\types\database\MDatabaseDatastoreException
  • webfilesframework\MWebfilesFrameworkException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace webfilesframework\core\datasystem\file\format;
  4: use webfilesframework\MWebfilesFrameworkException;
  5: 
  6: /**
  7:  * Base class for all webfile class definitions.<br />
  8:  * On the following <a href="http://sebastianmonzel.github.io/webfiles-framework-doc/webf/webf_01_defintion.html">link</a>
  9:  * you can find more information about the definition of webfiles.
 10:  *
 11:  * @author     Sebastian Monzel < mail@sebastianmonzel.de >
 12:  * @since      0.1.7
 13:  */
 14: class MWebfile {
 15: 
 16:     protected $m_iId = 0;
 17: 
 18:     /**
 19:      * @var int sets the time of the main context of the given webfile.
 20:      * Example:<br />
 21:      * An event would have the point when it takes place. An news entry
 22:      * would have the creation time as context time.
 23:      */
 24:     public $m_iTime;
 25: 
 26: 
 27:     /**
 28:      * Converts the current webfile into its xml representation.
 29:      *
 30:      * @param bool $usePreamble sets the option of using a preamble in xml - usually used for setting the version of xml an the encoding.
 31:      *
 32:      * @return string string returns the webfile as a marshalled String.
 33:      * @throws \ReflectionException
 34:      */
 35:     public function marshall($usePreamble = true)
 36:     {
 37:         $out = "";
 38:         $attributes = $this->getAttributes();
 39:         if ($usePreamble) {
 40:             $out .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 41:         }
 42:         $out .= "<object classname=\"" . static::classname() . "\">\n";
 43:         foreach ($attributes as $attribute) {
 44: 
 45:             $attributeName = $attribute->getName();
 46: 
 47:             if (MWebfile::isSimpleDatatype($attributeName)) {
 48:                 $attribute->setAccessible(true);
 49:                 $attributeFieldName = static::getSimplifiedAttributeName($attributeName);
 50:                 $out .= "\t<" . $attributeFieldName . "><![CDATA[" . $attribute->getValue($this) . "]]></" . $attributeFieldName . ">\n";
 51:             }
 52:         }
 53:         $out .= "</object>";
 54: 
 55:         return $out;
 56:     }
 57: 
 58:     /**
 59:      * Converts the given xml into a webfile object.
 60:      *
 61:      * @param string $data xml which represents a webfile.
 62:      *
 63:      * @throws MWebfilesFrameworkException
 64:      * @throws \ReflectionException
 65:      */
 66:     public function unmarshall($data)
 67:     {
 68:         static::genericUnmarshall($data,$this);
 69:     }
 70: 
 71:     /**
 72:      * Converts the given xml-String into a new webfile object.
 73:      *
 74:      * @param string $xmlAsString
 75:      *
 76:      * @return MWebfile
 77:      * @throws MWebfilesFrameworkException
 78:      * @throws \ReflectionException
 79:      */
 80:     public static function staticUnmarshall($xmlAsString)
 81:     {
 82:         return static::genericUnmarshall($xmlAsString);
 83:     }
 84: 
 85: 
 86:     /**
 87:      * @param      $xmlAsString
 88:      * @param null $targetObject
 89:      *
 90:      * @return MWebfile
 91:      * @throws MWebfilesFrameworkException
 92:      * @throws \ReflectionException
 93:      */
 94:     private static function genericUnmarshall($xmlAsString, &$targetObject = null) {
 95: 
 96:         $root = simplexml_load_string($xmlAsString);
 97: 
 98:         if ($root == null) {
 99:             throw new MWebfilesFrameworkException("Error on reading initial xml: " . $xmlAsString);
100:         }
101: 
102:         if ($root->getName() == "reference") {
103:             $url = $root->url;
104:             $xmlAsString = file_get_contents($url);
105:             $root = simplexml_load_string($xmlAsString);
106: 
107:             if ($root == null) {
108:                 throw new MWebfilesFrameworkException("Error on reading reference xml: " . $xmlAsString);
109:             }
110:         }
111: 
112:         if ( $targetObject == null ) {
113:             $classname = (string)$root->attributes()->classname;
114: 
115:             // INSTANCIATE NEW
116:             $ref = new \ReflectionClass($classname);
117:             $targetObject = $ref->newInstanceWithoutConstructor();
118:         }
119: 
120:         $objectAttributes = $root->children();
121:         $attributes = $targetObject->getAttributes();
122: 
123:         /** @var \SimpleXMLElement $value */
124:         foreach ($objectAttributes as $value) {
125:             /** @var \ReflectionProperty $attribute */
126:             foreach ($attributes as $attribute) {
127: 
128:                 $attribute->setAccessible(true);
129:                 $attributeName = $attribute->getName();
130:                 if ($value->getName() == static::getSimplifiedAttributeName($attributeName)) {
131:                     $attribute->setValue($targetObject, $value->__toString());
132:                 }
133:             }
134:         }
135:         return $targetObject;
136:     }
137: 
138:     /**
139:      * In case of using the current webfile object for making a request
140:      * on a datastore (getByTemplate()) this method helps to
141:      * set the defaults for making the template request.
142:      * @throws \ReflectionException
143:      */
144:     public function presetForTemplateSearch()
145:     {
146:         $attributes = $this->getAttributes();
147:         foreach ($attributes as $attribute) {
148: 
149:             $attributeName = $attribute->getName();
150: 
151:             if (MWebfile::isSimpleDatatype($attributeName)) {
152:                 $attribute->setAccessible(true);
153:                 $attribute->setValue($this, "[any]");
154:             }
155:         }
156:     }
157: 
158:     /**
159:      * @param MWebfile $template
160:      *
161:      * @return bool
162:      * @throws \ReflectionException
163:      */
164:     public function matchesTemplate(MWebfile $template) {
165: 
166:         if ( $template::classname() == static::classname() ) {
167: 
168:             $attributes = $template->getAttributes(true);
169: 
170:             /** @var \ReflectionProperty $attribute */
171:             foreach ($attributes as $attribute) {
172: 
173:                 $attribute->setAccessible(true);
174:                 $templateValue = $attribute->getValue($template);
175: 
176:                 if (
177:                     $templateValue != "[any]"
178:                     && !($templateValue instanceof MIDatastoreFunction)
179:                 ) {
180: 
181:                     $webfileValue = $attribute->getValue($this);
182:                     if ($templateValue != $webfileValue) {
183:                         return false;
184:                     }
185:                 }
186:             }
187:             return true;
188:         } else {
189:             return false;
190:         }
191: 
192:     }
193: 
194:     /**
195:      * returns true if attribute is a simple datatype (for example
196:      * string, integer or boolean).
197:      *
198:      * @param string $datatypeName
199:      * @return boolean
200:      */
201:     public static function isSimpleDatatype($datatypeName)
202:     {
203:         if (!self::isObject($datatypeName) && substr($datatypeName, 2, 1) != "_") {
204:             return true;
205:         } else {
206:             return false;
207:         }
208:     }
209: 
210:     /**
211:      * returns true if attribute is object in the other case the returnvalue is false
212:      * @param string $attributeName
213:      * @return boolean
214:      */
215:     public static function isObject($attributeName)
216:     {
217:         if (substr($attributeName, 2, 1) == "o") {
218:             return true;
219:         } else {
220:             return false;
221:         }
222: 
223:     }
224: 
225: 
226:     /**
227:      * eturns the attributes of the actual class which are relevant for the
228:      * webfile definition.
229:      *
230:      * @param bool $simpleDatatypesOnly
231:      *
232:      * @return \ReflectionProperty[]
233:      * @throws \ReflectionException
234:      */
235:     public static function getAttributes($simpleDatatypesOnly = false)
236:     {
237:         $oSelfReflection = new \ReflectionClass(static::classname());
238:         $oPropertyArray = $oSelfReflection->getProperties(
239:             \ReflectionProperty::IS_PUBLIC |
240:             \ReflectionProperty::IS_PROTECTED |
241:             \ReflectionProperty::IS_PRIVATE);
242: 
243:         $count = 0;
244:         while ($count < count($oPropertyArray)) {
245:             $sAttributeName = $oPropertyArray[$count]->getName();
246:             if (
247:                 // TODO generalize attribute prefix (sample "m_-s-", (start 2, length 1) )
248:                 substr($sAttributeName, 1, 1) != "_" ||
249:                 substr($sAttributeName, 2, 1) == "_" ||
250:                 ( $simpleDatatypesOnly && substr($sAttributeName, 2, 1) == "o")
251:             ) {
252:                 unset($oPropertyArray[$count]);
253:             }
254:             $count++;
255:         }
256:         return $oPropertyArray;
257:     }
258: 
259:     /**
260:      * Returns a xml defined class information. It contains the
261:      * classname and the given attributes.
262:      *
263:      * @return string xml with information about the class
264:      * @throws \ReflectionException
265:      */
266:     public static function getClassInformation()
267:     {
268: 
269:         $returnValue = "<classinformation>\n";
270:         $returnValue .= "\t<author>simpleserv.de</author>\n";
271:         $returnValue .= "\t<classname>" . static::classname() . "</classname>\n";
272:         $returnValue .= "\t<attributes>\n";
273: 
274:         $attributes = static::getAttributes();
275: 
276:         foreach ($attributes as $attribute) {
277: 
278:             $attributeName = $attribute->getName();
279: 
280:             if (MWebfile::isSimpleDatatype($attributeName)) {
281:                 $attributeFieldName = static::getSimplifiedAttributeName($attributeName);
282:                 $attributeFieldType = MWebfile::getDatatypeFromAttributeName($attributeName);
283:                 $returnValue .= "\t\t<attribute name=\"" . $attributeFieldName . "\" type=\"" . $attributeFieldType . "\" />\n";
284:             }
285: 
286: 
287:         }
288:         $returnValue .= "\t</attributes>\n";
289:         $returnValue .= "</classinformation>";
290:         return $returnValue;
291: 
292:     }
293: 
294:     /**
295:      *
296:      * Enter description here ...
297:      * @param string $attributeName
298:      * @return null|string
299:      */
300:     public static function getDatatypeFromAttributeName($attributeName)
301:     {
302:         // TODO generalize attribute prefix (sample "m_-s-", (start 2, length 1) )
303:         $datatypeToken = substr($attributeName, 2, 1);
304: 
305:         if ($datatypeToken == "s") {
306:             return "shorttext";
307:         } else if ($datatypeToken == "l") {
308:             return "longtext";
309:         } else if ($datatypeToken == "h") {
310:             return "htmllongtext";
311:         } else if ($datatypeToken == "d") {
312:             return "date";
313:         } else if ($datatypeToken == "t") {
314:             return "time";
315:         } else if ($datatypeToken == "i") {
316:             return "integer";
317:         } else if ($datatypeToken == "f") {
318:             return "float";
319:         } else if ($datatypeToken == "o") {
320:             return "object";
321:         }
322:         return null;
323:     }
324: 
325:     /**
326:      * Transforms the actual webfile into an dataset. A dataset is represented by a key value array.
327:      * The key is the attributes name. The value is the attributes value.
328:      *
329:      * @return array
330:      * @throws \ReflectionException
331:      */
332:     public function getDataset()
333:     {
334:         $dataset = array();
335: 
336:         $attributes = $this->getAttributes();
337: 
338:         foreach ($attributes as $attribute) {
339: 
340:             $attributeName = $attribute->getName();
341:             $attribute->setAccessible(true);
342:             $attributeValue = $attribute->getValue($this);
343: 
344:             if (MWebfile::isSimpleDatatype($attributeName)) {
345:                 $attributeFieldName = static::getSimplifiedAttributeName($attributeName);
346:                 $dataset[$attributeFieldName] = $attributeValue;
347:             }
348:         }
349:         return $dataset;
350:     }
351: 
352: 
353:     /**
354:      * Returns database field name to a given attribute
355:      *
356:      * @param string $p_sFieldName
357:      * @return string
358:      */
359:     public static function getSimplifiedAttributeName($p_sFieldName)
360:     {
361:         // TODO generalize attribute prefix (sample "m_-s-", (start 2, length 1) )
362:         $sDatabaseFieldName = substr($p_sFieldName, 3);
363:         $sDatabaseFieldName = strtolower($sDatabaseFieldName);
364:         return $sDatabaseFieldName;
365:     }
366: 
367:     public function getId()
368:     {
369:         return $this->m_iId;
370:     }
371: 
372:     public function setId($itemId)
373:     {
374:         $this->m_iId = $itemId;
375:     }
376: 
377:     /**
378:      *
379:      */
380:     public function getTime()
381:     {
382:         return $this->m_iTime;
383:     }
384: 
385:     /**
386:      * @param $time int unix timestamp of the context time.
387:      */
388:     public function setTime($time)
389:     {
390:         $this->m_iTime = $time;
391:     }
392: 
393:     public function getGeograficPosition()
394:     {
395:         return NULL;
396:     }
397: 
398:     public static function classname() {
399:         return get_called_class();
400:     }
401: 
402:     /**
403:      * @param $classname
404:      *
405:      * @return MWebfile
406:      * @throws MWebfilesFrameworkException
407:      * @throws \ReflectionException
408:      */
409:     public static function createWebfileByClassname($classname) {
410:         $ref = new \ReflectionClass($classname);
411:         $webfile = $ref->newInstanceWithoutConstructor();
412:         if (! $webfile instanceof MWebfile ) {
413:             throw new MWebfilesFrameworkException("given class '" . $classname . " does not extend MWebfile.");
414:         }
415:         return $webfile;
416:     }
417: 
418: }
API documentation generated by ApiGen