lazyrecord\schema\DeclareSchema::isNewerThanFile PHP Method

isNewerThanFile() public method

isNewerThanFile returns true if the schema file is newer than a file.
public isNewerThanFile ( string $path ) : boolean
$path string
return boolean
    public function isNewerThanFile($path)
    {
        if (!file_exists($path)) {
            return true;
        }
        return $this->getModificationTime() > filemtime($path);
    }

Usage Example

 /**
  * This method checks the exising schema file and the generated class file mtime.
  * If the schema file is newer or the forceUpdate flag is specified, then 
  * the generated class files should be updated.
  *
  * @param ClassTemplate\ClassFile $cTemplate
  * @param DeclareSchema           $schema
  */
 protected function updateClassFile(ClassFile $cTemplate, DeclareSchema $schema, $canOverwrite = false)
 {
     // always update the proxy schema file
     $classFilePath = $schema->getRelatedClassPath($cTemplate->getShortClassName());
     // classes not Model/Collection class are overwriteable
     if (file_exists($classFilePath)) {
         if ($canOverwrite && ($schema->isNewerThanFile($classFilePath) || $this->forceUpdate)) {
             $this->writeClassTemplateToPath($cTemplate, $classFilePath);
             return [$cTemplate->getClassName(), $classFilePath];
         }
     } else {
         if ($this->writeClassTemplateToPath($cTemplate, $classFilePath)) {
             return [$cTemplate->getClassName(), $classFilePath];
         }
     }
 }
All Usage Examples Of lazyrecord\schema\DeclareSchema::isNewerThanFile