ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

Functions
package_manipulation.php File Reference

Go to the source code of this file.

## Functions
| _load_packages_list ($ROOT_DIR=INSTALL_DIR)
| _get_name_and_version ($RootPackage= '', $RootVersion= '')
| _fetch_subpackages_list ($RetArray, $ROOT_DIR, $p, $PackageNamePrefix, $PackageVersionPrefix)
| _get_packages_list ($ROOT_DIR=INSTALL_DIR, $RootPackage= '', $RootVersion= '')
| _fetch_subpackages ($ROOT_DIR, $p, $PackageNamePrefix, $PackageVersionPrefix)
| _fetch_subpackages_tree ($RetArray, $ROOT_DIR, $p, $PackageNamePrefix, $PackageVerPrefix)
| _get_packages_tree ($ROOT_DIR=INSTALL_DIR, $RootPackage= '', $RootVersion= '')
| _unzip_package ($FileSource, $ROOT_DIR=INSTALL_DIR)
| _install_package ($FileSource, $ROOT_DIR=INSTALL_DIR)
| _get_packages_info ($PackageName, $PackageVersion, $ROOT_DIR=INSTALL_DIR)
| _delete_pf ($Path)
| _open_package_list ($Path)
| _delete_package ($PackageName, $PackageVersion, $ROOT_DIR=INSTALL_DIR)

## Function Documentation

_delete_package | ( |  | $PackageName,
|  |  | $PackageVersion,
|  |  | $ROOT_DIR = `INSTALL_DIR`
| ) |  |

Delete package by given name and version.

Parameters

  $PackageName | - Package's name.
  $PackageVersion | - Package's version.
  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 671 of file package_manipulation.php.

{
try
{
global $PackageCache;
$PackageCache = array();
$Handle = _open_package_list( $ROOT_DIR.'/packages/core/data/package_list' );
$PackagesInfo = _get_packages_info( $PackageName , $PackageVersion , $ROOT_DIR );
foreach( $PackagesInfo as $pi )
{
$PackageNameAndVersion = explode( '#' , $pi );
if( $PackageNameAndVersion[ 0 ] === $PackageName.'.'.$PackageVersion )
{
_delete_pf( $ROOT_DIR.'/packages/'.$PackageNameAndVersion[ 1 ] );
}
else
{
$pi .= "\r\n";
fwrite( $Handle , $pi , strlen( $pi ) );
}
}
fclose( $Handle );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_delete_pf | ( |  | $Path | ) |

Delete package by given name and version.

Parameters

  $Path | - Path to the package.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 595 of file package_manipulation.php.

{
try
{
_rmdir_recurse( $Path );
@rmdir( $Path );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_fetch_subpackages | ( |  | $ROOT_DIR,
|  |  | $p,
|  |  | $PackageNamePrefix,
|  |  | $PackageVersionPrefix
| ) |  |

Function returns a list of installed packages.

Parameters

  $ROOT_DIR | - Root directory path.
  $p | - Processing package's info.
  $PackageNamePrefix | - Package name prefix.
  $PackageVersionPrefix | - Package version prefix.

Returns
  List of packages.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 283 of file package_manipulation.php.

{
try
{
$InfoParts = explode( '.' , $p[ 0 ] );
$SubPackages = array();
if( file_exists( $ROOT_DIR.'/packages/'.$p[ 1 ].'/packages/core/data/package_list' ) )
{
$Name = $PackageNamePrefix.$InfoParts[ 0 ];
$Version = $PackageVersionPrefix.$InfoParts[ 1 ].'.'.$InfoParts[ 2 ].'.'.$InfoParts[ 3 ];
$SubPackages = _get_packages_tree( $ROOT_DIR.'/packages/'.$p[ 1 ] , $Name , $Version );
}
return( $SubPackages );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_fetch_subpackages_list | ( |  | $RetArray,
|  |  | $ROOT_DIR,
|  |  | $p,
|  |  | $PackageNamePrefix,
|  |  | $PackageVersionPrefix
| ) |  |

Function returns a list of installed packages.

Parameters

  $RetArray | - Already fetched packages.
  $ROOT_DIR | - Root directory path.
  $p | - Processing package's info.
  $PackageNamePrefix | - Package name prefix.
  $PackageVersionPrefix | - Package version prefix.

Returns
  List of packages.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 166 of file package_manipulation.php.

{
try
{
$InfoParts = explode( '.' , $p[ 0 ] );
$RetArray [] = array(
'package_name' => $PackageNamePrefix.$InfoParts[ 0 ] ,
'package_version' => $PackageVersionPrefix.$InfoParts[ 1 ].'.'.$InfoParts[ 2 ].'.'.$InfoParts[ 3 ]
);
if( file_exists( $ROOT_DIR.'/packages/'.$p[ 1 ].'/packages/core/data/package_list' ) )
{
$Name = $PackageNamePrefix.$InfoParts[ 0 ];
$Version = $PackageVersionPrefix.$InfoParts[ 1 ].'.'.$InfoParts[ 2 ].'.'.$InfoParts[ 3 ];
$RetArray = array_merge(
$RetArray , _get_packages_list( $ROOT_DIR.'/packages/'.$p[ 1 ] , $Name , $Version )
);
}
return( $RetArray );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_fetch_subpackages_tree | ( |  | $RetArray,
|  |  | $ROOT_DIR,
|  |  | $p,
|  |  | $PackageNamePrefix,
|  |  | $PackageVerPrefix
| ) |  |

Function returns a list of installed packages.

Parameters

  $RetArray | - Already fetched packages.
  $ROOT_DIR | - Root directory path.
  $p | - Processing package's info.
  $PackageNamePrefix | - Package name prefix.
  $PackageVerPrefix | - Package version prefix.

Returns
  List of packages.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 344 of file package_manipulation.php.

{
try
{
$SubPackages = _fetch_subpackages( $ROOT_DIR , $p , $PackageNamePrefix , $PackageVerPrefix );
$InfoParts = explode( '.' , $p[ 0 ] );
$RetArray [] = array(
'package_signature' => $p[ 0 ] ,
'package_name' => $InfoParts[ 0 ] ,
'package_version' => $InfoParts[ 1 ].'.'.$InfoParts[ 2 ].'.'.$InfoParts[ 3 ] ,
'subpackages' => $SubPackages ,
'full_package_name' => $PackageNamePrefix.$InfoParts[ 0 ] ,
'full_package_version' => $PackageVerPrefix.$InfoParts[ 1 ].'.'.$InfoParts[ 2 ].'.'.
$InfoParts[ 3 ]
);
return( $RetArray );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_get_name_and_version | ( |  | $RootPackage = `''`,
|  |  | $RootVersion = `''`
| ) |  |

Function returns package name and version.

Parameters

  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.
  $RootPackage | - Root package.
  $RootVersion | - Version of the root package

Returns
  Package name and version.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 98 of file package_manipulation.php.

{
try
{
if( $RootPackage == '' )
{
$PackageNamePrefix = '';
}
else
{
$PackageNamePrefix = $RootPackage.'::';
}
if( $RootVersion == '' )
{
$PackageVersionPrefix = '';
}
else
{
$PackageVersionPrefix = $RootVersion.'::';
}
return( array( $PackageNamePrefix , $PackageVersionPrefix ) );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_get_packages_info | ( |  | $PackageName,
|  |  | $PackageVersion,
|  |  | $ROOT_DIR = `INSTALL_DIR`
| ) |  |

Function returns data from the packages_list file.

Parameters

  $PackageName | - Package's name.
  $PackageVersion | - Package's version.
  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.

Returns
  Data from the packages_list file.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 553 of file package_manipulation.php.

{
try
{
$File = _file_get_contents( $ROOT_DIR.'/packages/core/data/package_list' );
if( $File === false )
{
throw(
new Exception( 'An error occured while loading file '.$ROOT_DIR.'/packages/core/data/package_list' )
);
}
$File = str_replace( "\r" , "\n" , $File );
$File = str_replace( "\n\n" , "\n" , $File );
return( explode( "\n" , $File ) );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_get_packages_list | ( |  | $ROOT_DIR = `INSTALL_DIR`,
|  |  | $RootPackage = `''`,
|  |  | $RootVersion = `''`
| ) |  |

Function returns a list of installed packages.

Parameters

  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.
  $RootPackage | - Root package.
  $RootVersion | - Version of the root package

Returns
  List of packages.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 224 of file package_manipulation.php.

{
try
{
$PackageList = _load_packages_list( $ROOT_DIR );
list( $PackageNamePrefix , $PackageVersionPrefix ) = _get_name_and_version( $RootPackage , $RootVersion );
$RetArray = array();
foreach( $PackageList as $p )
{
$RetArray = _fetch_subpackages_list(
$RetArray , $ROOT_DIR , $p , $PackageNamePrefix , $PackageVersionPrefix
);
}
return( $RetArray );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_get_packages_tree | ( |  | $ROOT_DIR = `INSTALL_DIR`,
|  |  | $RootPackage = `''`,
|  |  | $RootVersion = `''`
| ) |  |

Function returns a list of installed packages.

Parameters

  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.
  $RootPackage | - Root package.
  $RootVersion | - Version of the root package

Returns
  List of packages.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 399 of file package_manipulation.php.

{
try
{
$PackageList = _load_packages_list( $ROOT_DIR );
list( $PackageNamePrefix , $PackageVersionPrefix ) = _get_name_and_version( $RootPackage , $RootVersion );
$RetArray = array();
foreach( $PackageList as $p )
{
$RetArray = _fetch_subpackages_tree(
$RetArray , $ROOT_DIR , $p , $PackageNamePrefix , $PackageVersionPrefix
);
rsort_by_field( $RetArray , 'package_signature' );
}
return( $RetArray );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_install_package | ( |  | $FileSource,
|  |  | $ROOT_DIR = `INSTALL_DIR`
| ) |  |

Function installs package.

Parameters

  $FileSource | - The source of package file.
  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.

Returns
  Name of the root directory. In this directory all package processing will be run.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 505 of file package_manipulation.php.

{
try
{
$FileSource = strtolower( $FileSource );
$SubDirPath = md5( date( 'YmdHis' ).$FileSource );
mkdir( $ROOT_DIR.'/packages/'.$SubDirPath );
_unzip_package( $FileSource , $ROOT_DIR );
return( $ROOT_DIR.'/packages/'.$SubDirPath );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_load_packages_list | ( |  | $ROOT_DIR = `INSTALL_DIR` | ) |

Function returns a list of installed packages.

Parameters

  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.

Returns
  List of packages.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 38 of file package_manipulation.php.

{
try
{
$File = _file_get_contents( $ROOT_DIR.'/packages/core/data/package_list' );
if( $File === false )
{
throw(
new Exception( 'An error occured while loading file '.$ROOT_DIR.'/packages/core/data/package_list' )
);
}
$File = str_replace( "\r" , "\n" , $File );
$File = str_replace( "\n\n" , "\n" , $File );
$PackagesInfo = explode( "\n" , $File );
$PackageList = array();
foreach( $PackagesInfo as $pi )
{
$PackageList [] = explode( '#' , $pi );
$tmp = explode( '#' , $pi );
}
return( $PackageList );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_open_package_list | ( |  | $Path | ) |

Delete package by given name and version.

Parameters

  $Path | - Path to the package.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 626 of file package_manipulation.php.

{
try
{
$Handle = fopen( $Path , 'w' );
if( $Handle === false )
{
throw( new Exception( 'Unable to open package list' ) );
}
return( $Handle );
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}

_unzip_package | ( |  | $FileSource,
|  |  | $ROOT_DIR = `INSTALL_DIR`
| ) |  |

Function installs package.

Parameters

  $FileSource | - The source of package file.
  $ROOT_DIR | - Name of the root directory. In this directory all package processing will be run.

Returns
  Name of the root directory. In this directory all package processing will be run.

Exceptions

  Exception | An exception of this type is thrown.

Author
  Dodonov A.A.

Definition at line 452 of file package_manipulation.php.

{
try
{
$Zip = new ZipArchive;
if( $Zip->open( $FileSource ) === false )
{
throw( new Exception( 'An error occured while opening package '.$FileSource ) );
}
if( $Zip->extractTo( $ROOT_DIR.'/packages/'.$SubDirPath.'/' ) === false )
{
throw( new Exception( 'An error occured while extracting package '.$FileSource ) );
}
@unlink( $FileSource );
$PackageList = _file_get_contents( $ROOT_DIR.'/packages/core/data/package_list' );
file_put_contents(
$ROOT_DIR.'/packages/core/data/package_list' ,
basename( $FileSource , '.zip' ).'#'.$SubDirPath."\r\n".$PackageList
);
$Zip->close();
}
catch( Exception $e )
{
$Args = func_get_args();throw( _get_exception_object( __FUNCTION__ , $Args , $e ) );
}
}