1+ # !/usr/bin/env perl
2+
3+ use strict;
4+ use warnings;
5+ use File::Find;
6+ use File::Basename;
7+ use File::Slurp;
8+ use Cwd qw( abs_path) ;
9+ use v5.12;
10+
11+ my $root = dirname(abs_path(__FILE__ . ' /..' ));
12+
13+ my @dir_to_search = (
14+ $root . ' /src' ,
15+ $root . ' /util' ,
16+ $root . ' /tests'
17+ );
18+
19+ my $header = <<EOL ;
20+ /**
21+ * Elasticsearch PHP client
22+ *
23+ * \@ link https://github.com/elastic/elasticsearch-php/
24+ * \@ copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
25+ * \@ license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
26+ * \@ license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1
27+ *
28+ * Licensed to Elasticsearch B.V under one or more agreements.
29+ * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or
30+ * the GNU Lesser General Public License, Version 2.1, at your option.
31+ * See the LICENSE file in the project root for more information.
32+ */
33+ EOL
34+
35+ my @suffix = (' .php' );
36+ my %hash = map {$_ => 1} @suffix ;
37+
38+ say " SEARCH for PHP files..." ;
39+ find(\&add_header, @dir_to_search );
40+ say " END" ;
41+
42+ sub add_header {
43+ my ($filename , $dirs , $suffix ) = fileparse($File::Find::name , @suffix );
44+
45+ return if !$hash {$suffix };
46+
47+ my $file_content = read_file($File::Find::name );
48+ if (index ($file_content , $header ) == -1) {
49+ printf (" \t Adding header to %s \n " , $File::Find::name );
50+
51+ my @phpdoc_to_remove = (
52+ ' author' ,
53+ ' category' ,
54+ ' package' ,
55+ ' license' ,
56+ ' link' ,
57+ );
58+
59+ # Remove previous @phpdocumentor tag
60+ foreach my $tag ( @phpdoc_to_remove ) {
61+ $file_content =~ s /\s\*\s\@ $tag.*\n // g ;
62+ }
63+ # Insert the $header at the top of the file
64+ $file_content =~ s / <\? php/ <\? php\n $header / ;
65+
66+ write_file($File::Find::name , $file_content );
67+ }
68+ }
0 commit comments