2020-03-22 16:55:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  ERequirementNotMet  extends  Exception  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2020-03-22 16:55:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-04 17:25:24 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  REQUIRED_PHP_EXTENSIONS  =  [ 'fileinfo' ,  'pdo_sqlite' ,  'gd' ,  'ctype' ,  'json' ,  'intl' ,  'zlib' ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// These are core extensions, so normally can't be missing, but seems to be the case, however, on FreeBSD
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									'filter' ,  'iconv' ,  'tokenizer' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								];  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-12-22 21:54:49 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  REQUIRED_SQLITE_VERSION  =  '3.9.0' ;  
						 
					
						
							
								
									
										
										
										
											2020-03-22 16:55:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-22 18:02:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								class  PrerequisiteChecker  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									public  function  checkRequirements () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										self :: checkForConfigFile (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										self :: checkForConfigDistFile (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										self :: checkForComposer (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										self :: checkForPhpExtensions (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										self :: checkForSqliteVersion (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-22 16:55:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									private  function  checkForComposer () 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! file_exists ( __DIR__  .  '/../vendor/autoload.php' )) 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											throw  new  ERequirementNotMet ( '/vendor/autoload.php not found. Have you run Composer?' ); 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-22 16:55:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									private  function  checkForConfigDistFile () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! file_exists ( __DIR__  .  '/../config-dist.php' )) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw  new  ERequirementNotMet ( 'config-dist.php not found. Please do not remove this file.' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-29 19:54:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									private  function  checkForConfigFile () 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! file_exists ( GROCY_DATAPATH  .  '/config.php' )) 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											throw  new  ERequirementNotMet ( 'config.php in data directory ('  .  GROCY_DATAPATH  .  ') not found. Have you copied config-dist.php to the data directory and renamed it to config.php?' ); 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-29 19:54:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									private  function  checkForPhpExtensions () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$loadedExtensions  =  get_loaded_extensions (); 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										foreach  ( REQUIRED_PHP_EXTENSIONS  as  $extension ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! in_array ( $extension ,  $loadedExtensions )) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												throw  new  ERequirementNotMet ( " PHP module ' { $extension } ' not installed, but required. " ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									private  function  checkForSqliteVersion () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$sqliteVersion  =  self :: getSqlVersionAsString (); 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-29 16:41:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( version_compare ( $sqliteVersion ,  REQUIRED_SQLITE_VERSION ,  '<' )) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw  new  ERequirementNotMet ( 'SQLite '  .  REQUIRED_SQLITE_VERSION  .  ' is required, however you are running '  .  $sqliteVersion ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-04-29 19:54:05 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-31 20:40:31 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									private  function  getSqlVersionAsString () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										$dbh  =  new  PDO ( 'sqlite::memory:' ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  $dbh -> query ( 'select sqlite_version()' ) -> fetch ()[ 0 ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2020-03-22 16:55:23 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}