Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Zapisuje zadane dane do pliku w formie łatwego do odczytu pliku PHP
- *
- * @param $file string Ścieżka absolutna do pliku, który zostanie zapisany
- * @param $data mixed Dane, które zostaną wyeksportowane do pliku
- * @return void
- */
- function exportVariable2PHPFile(array $data, $file)
- {
- makeFile($file);
- $date = date('Y-m-d H:i:s');
- $export = var_export($data, true);
- $content = "<?php\n\n/** @generated {$date} */\n\nreturn {$export};";
- file_put_contents($file, $content);
- }
- /**
- * Wyszukuje plików na dysku
- *
- * @param $pattern string Wyrażenie, tak samo jak w glob
- * @param int $flags Flagi, tak samo jak w przypadku glob
- * @return array Zwraca płaską tablicę z ścieżkami do znalezionych plików
- */
- function globRecursive($pattern, $flags = 0)
- {
- $files = glob($pattern, $flags);
- foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
- $files = array_merge($files, globRecursive($dir . '/' . basename($pattern), $flags));
- }
- return $files;
- }
- /**
- * Tworzy rekursywnie katalogi w ścieżce
- *
- * @param $path string Ścieżka absolutna do katalogów które chcesz stworzyć
- * @param int $mode Prawa dostępu do katalogu
- * @return void
- */
- function makeDirsRecursive($path, $mode = 0777)
- {
- $path = rtrim($path, '/');
- if (empty($path)) {
- return;
- }
- $dirs = explode('/', $path);
- $dir = '';
- foreach ($dirs as $part) {
- $dir .= $part . '/';
- if (is_dir($dir)) {
- continue;
- }
- mkdir($dir, $mode);
- }
- }
- /**
- * Tworzy plik oraz katalogi, jeżeli ich brakuje
- *
- * @param $filepath string Ścieżka absolutna do pliku, który chcesz stworzyć
- * @param int $mode Prawa dostępu do pliku
- * @return void
- */
- function makeFile($filepath, $mode = 0775)
- {
- makeDirsRecursive(dirname($filepath), 0777);
- if (!file_exists($filepath)) {
- touch($filepath);
- }
- chmod($filepath, $mode);
- }
- /**
- * Zamienia litery za średnikami na wielkie. Usuwa myśliki
- *
- * /example-request => /exampleRequest
- *
- * @param $string string Dowolny ciąg znaków
- * @return string Zamieniony tekst
- */
- function transformHyphen2CamelCase($string)
- {
- return preg_replace_callback('~\-([.])~', function ($matches) {
- return strtoupper($matches[1]);
- }, $string);
- }
- /**
- * Zamienia wielkie litery na małe i dodaje przed nimi średniki
- *
- * /exampleRequest => /example-request
- *
- * @param $string string Dowolny ciąg znaków
- * @return string Zamieniony tekst
- */
- function transformCamelCase2Hyphen($string)
- {
- return trim(preg_replace_callback('~([A-Z])~', function ($matches) {
- return '-'.strtolower($matches[1]);
- }, $string), '-');
- }
- function debugXMLReader(XMLReader $xml)
- {
- $nodeTypes = [
- 0 => 'NONE',
- 1 => 'ELEMENT',
- 2 => 'ATTRIBUTE',
- 3 => 'TEXT',
- 4 => 'CDATA',
- 5 => 'ENTITY_REF',
- 6 => 'ENTITY',
- 7 => 'PI',
- 8 => 'COMMENT',
- 9 => 'DOC',
- 10 => 'DOC_TYPE',
- 11 => 'DOC_FRAGMENT',
- 12 => 'NOTATION',
- 13 => 'WHITESPACE',
- 14 => 'SIGNIFICANT_WHITESPACE',
- 15 => 'END_ELEMENT',
- 16 => 'END_ENTITY',
- 17 => 'XML_DECLARATION',
- ];
- $properties = [
- 'name',
- 'localName',
- 'attributeCount',
- 'depth',
- 'hasAttributes',
- 'hasValue',
- 'isDefault',
- 'isEmptyElement',
- 'prefix',
- 'xmlLang',
- 'namespaceURI',
- 'baseURI',
- 'value',
- ];
- echo "==================================================\n";
- echo "nodeType : ({$xml->nodeType}) {$nodeTypes[$xml->nodeType]}\n";
- foreach ($properties as $property) {
- printf("%-14s : %s(%s)\n", $property, gettype($xml->{$property}), var_export($xml->{$property}, true));
- }
- echo "readInnerXML() : {$xml->readInnerXml()}\n";
- echo "readOuterXML() : {$xml->readOuterXml()}\n";
- echo "readString() : {$xml->readString()}\n";
- echo "\n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement