How does the CRISPR system protect bacteria from phage infection?

How does the CRISPR system protect bacteria from phage infection?