-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
157 changed files
with
15,475 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
$vendorDir = __DIR__ . '/vendor_prefixed'; | ||
$autoloadFile = $vendorDir . '/autoload.php'; | ||
|
||
$files = array(); | ||
|
||
$directory = new RecursiveDirectoryIterator( $vendorDir, RecursiveDirectoryIterator::SKIP_DOTS ); | ||
$iterator = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::SELF_FIRST ); | ||
|
||
// Function to strip comments from PHP code | ||
function strip_comments( $source ) { | ||
// Regular expressions for removing single-line and multi-line comments | ||
$singleLineCommentPattern = '/\/\/.*$/m'; | ||
$multiLineCommentPattern = '/\/\*.*?\*\//s'; | ||
// Remove the comments from the source code | ||
$source = preg_replace( $singleLineCommentPattern, '', $source ); | ||
$source = preg_replace( $multiLineCommentPattern, '', $source ); | ||
return $source; | ||
} | ||
|
||
foreach ( $iterator as $file ) { | ||
if ( $file->isFile() && $file->getExtension() === 'php' ) { | ||
$relativePath = str_replace( $vendorDir . '/', '', $file->getPathname() ); | ||
|
||
// Read the namespace and class name from the file | ||
$fileContent = file_get_contents( $file->getPathname() ); | ||
|
||
// Strip comments from the file content | ||
$fileContent = strip_comments( $fileContent ); | ||
|
||
$namespace = ''; | ||
$class = ''; | ||
|
||
if ( preg_match( '/namespace\s+([^;\s]+)\s*;/', $fileContent, $matches ) ) { | ||
$namespace = $matches[1]; | ||
} | ||
if ( preg_match( '/\b(class|interface|trait)\s+([^\s{]+)/', $fileContent, $classMatches ) ) { | ||
$class = $classMatches[2]; | ||
} | ||
|
||
// Only add valid class mappings | ||
if ( $namespace && $class ) { | ||
$fullClassName = $namespace . '\\' . $class; | ||
echo 'Found class: ' . $fullClassName . PHP_EOL; | ||
$files[ $fullClassName ] = './' . $relativePath; | ||
} | ||
} | ||
} | ||
|
||
echo 'Number of entries in files array: ' . count( $files ) . PHP_EOL; | ||
|
||
$autoloadContent = "<?php\n\n"; | ||
$autoloadContent .= "// autoload.php @generated by Composer\n\n"; | ||
$autoloadContent .= "\$classMap = [\n"; | ||
|
||
foreach ( $files as $className => $path ) { | ||
$autoloadContent .= " '$className' => '$path',\n"; | ||
} | ||
|
||
$autoloadContent .= "];\n\n"; | ||
$autoloadContent .= "spl_autoload_register(function (\$class) use (\$classMap) {\n"; | ||
$autoloadContent .= " if (isset(\$classMap[\$class])) {\n"; | ||
$autoloadContent .= " require __DIR__ . '/' . \$classMap[\$class];\n"; | ||
$autoloadContent .= " }\n"; | ||
$autoloadContent .= "});\n"; | ||
|
||
file_put_contents( $autoloadFile, $autoloadContent ); | ||
|
||
echo "Autoload file generated at $autoloadFile\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Cache Helper class | ||
*/ | ||
|
||
namespace WCPOS\WooCommercePOS\Services; | ||
|
||
use WCPOS\Vendor\Phpfastcache\Drivers\Files\Config; | ||
use WCPOS\Vendor\Phpfastcache\Drivers\Files\Driver; | ||
use WCPOS\Vendor\Phpfastcache\EventManager; | ||
use WCPOS\Vendor\Phpfastcache\Helper\Psr16Adapter; | ||
|
||
/** | ||
* | ||
*/ | ||
class Cache { | ||
/** | ||
* Get the cache instance | ||
* | ||
* @param string $instance_id Instance ID. | ||
* | ||
* @return Psr16Adapter | ||
*/ | ||
public static function get_cache_instance( string $instance_id = 'default' ) { | ||
static $cache = null; | ||
|
||
if ( $cache === null ) { | ||
$upload_dir = wp_upload_dir(); | ||
$cache_dir = $upload_dir['basedir'] . '/woocommerce_pos_cache'; | ||
|
||
if ( ! file_exists( $cache_dir ) ) { | ||
wp_mkdir_p( $cache_dir ); | ||
} | ||
|
||
$config = new Config( | ||
array( | ||
'path' => $cache_dir, | ||
) | ||
); | ||
|
||
$event_manager = EventManager::getInstance(); | ||
|
||
// Generate a unique instance ID for each logged-in user. | ||
$driver = new Driver( $config, $instance_id ); | ||
$driver->setEventManager( $event_manager ); | ||
|
||
$cache = new Psr16Adapter( $driver ); | ||
} | ||
|
||
return $cache; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.