jdt 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +64 -0
- data/LICENSE +7 -0
- data/README.md +101 -0
- data/Rakefile +2 -0
- data/bin/jdt +16 -0
- data/features/build.feature +0 -0
- data/features/manifest.feature +25 -0
- data/features/new.feature +97 -0
- data/features/release.feature +47 -0
- data/features/status.feature +22 -0
- data/features/step_definitions/my_steps.rb +37 -0
- data/features/support/env.rb +7 -0
- data/features/support/setup.rb +2 -0
- data/features/validate.feature +0 -0
- data/features/version.feature +9 -0
- data/jdt.gemspec +25 -0
- data/lib/jdt/cli.rb +34 -0
- data/lib/jdt/commands/build.rb +28 -0
- data/lib/jdt/commands/bump.rb +37 -0
- data/lib/jdt/commands/install.rb +20 -0
- data/lib/jdt/commands/new.rb +31 -0
- data/lib/jdt/commands/pretty_print.rb +16 -0
- data/lib/jdt/commands/secure.rb +19 -0
- data/lib/jdt/commands/status.rb +21 -0
- data/lib/jdt/commands/validate.rb +35 -0
- data/lib/jdt/commands/version.rb +18 -0
- data/lib/jdt/generator/generator.rb +262 -0
- data/lib/jdt/generator/templates/access.xml.erb +10 -0
- data/lib/jdt/generator/templates/component/admin/access.xml.erb +0 -0
- data/lib/jdt/generator/templates/component/admin/com_name.erb +0 -0
- data/lib/jdt/generator/templates/component/admin/config.xml.erb +0 -0
- data/lib/jdt/generator/templates/component/admin/controller.erb +0 -0
- data/lib/jdt/generator/templates/component/admin/views/view_name/tmpl/default.erb +0 -0
- data/lib/jdt/generator/templates/component/admin/views/view_name/view.html.erb +0 -0
- data/lib/jdt/generator/templates/component/index.html.erb +1 -0
- data/lib/jdt/generator/templates/component/manifest.xml.erb +46 -0
- data/lib/jdt/generator/templates/component/script.php.erb +66 -0
- data/lib/jdt/generator/templates/component/site/com_name.php.erb +15 -0
- data/lib/jdt/generator/templates/component/site/controller.php.erb +14 -0
- data/lib/jdt/generator/templates/component/site/models/com_model_name.erb +0 -0
- data/lib/jdt/generator/templates/component/site/views/view_name/tmpl/default.php.erb +0 -0
- data/lib/jdt/generator/templates/component/site/views/view_name/tmpl/default.xml.erb +0 -0
- data/lib/jdt/generator/templates/component/site/views/view_name/view.html.erb +0 -0
- data/lib/jdt/generator/templates/config.xml.erb +6 -0
- data/lib/jdt/generator/templates/controller.php.erb +13 -0
- data/lib/jdt/generator/templates/dummy_html.erb +1 -0
- data/lib/jdt/generator/templates/entry.erb +15 -0
- data/lib/jdt/generator/templates/manifest.xml.erb +59 -0
- data/lib/jdt/generator/templates/module/helper.php.erb +14 -0
- data/lib/jdt/generator/templates/module/manifest.xml.erb +16 -0
- data/lib/jdt/generator/templates/module/mod_name.php.erb +10 -0
- data/lib/jdt/generator/templates/module/tmpl/default.php.erb +3 -0
- data/lib/jdt/generator/templates/plugin/main.php.erb +0 -0
- data/lib/jdt/generator/templates/plugin/manifest.xml.erb +16 -0
- data/lib/jdt/generator/templates/script.php.erb +66 -0
- data/lib/jdt/generator.rb +1 -0
- data/lib/jdt/manifest/attributes.rb +77 -0
- data/lib/jdt/manifest/build.rb +106 -0
- data/lib/jdt/manifest/bump.rb +40 -0
- data/lib/jdt/manifest/find.rb +58 -0
- data/lib/jdt/manifest/library_manifest.rb +19 -0
- data/lib/jdt/manifest/manifest.rb +29 -0
- data/lib/jdt/manifest/referenced.rb +96 -0
- data/lib/jdt/manifest/schemas/library.xsd +80 -0
- data/lib/jdt/manifest/schemas/manifest.xsd +32 -0
- data/lib/jdt/manifest/secure.rb +39 -0
- data/lib/jdt/manifest/validation.rb +121 -0
- data/lib/jdt/manifest/xslts/pretty_print.xsl +46 -0
- data/lib/jdt/manifest.rb +9 -0
- data/lib/jdt/version.rb +3 -0
- data/lib/jdt.rb +0 -0
- data/lib/not_yet_added/deploy.rb +54 -0
- data/lib/not_yet_added/xampp.rb +82 -0
- data/spec/jdt/generator/generator_spec.rb +55 -0
- data/spec/jdt/manifest/data/example_library/.gitignore +1 -0
- data/spec/jdt/manifest/data/example_library/ActiveRecord.php +3 -0
- data/spec/jdt/manifest/data/example_library/JoomlaActiveRecord.php +56 -0
- data/spec/jdt/manifest/data/example_library/JoomlaConfig.php +42 -0
- data/spec/jdt/manifest/data/example_library/README.md +51 -0
- data/spec/jdt/manifest/data/example_library/dist/asdf.txt +0 -0
- data/spec/jdt/manifest/data/example_library/manifest.xml +22 -0
- data/spec/jdt/manifest/data/library.xml +33 -0
- data/spec/jdt/manifest/data/library_error.xml +23 -0
- data/spec/jdt/manifest/data/library_minimum.xml +11 -0
- data/spec/jdt/manifest/data/manifest.xml +4 -0
- data/spec/jdt/manifest/example_library_spec.rb +27 -0
- data/spec/jdt/manifest/finder_spec.rb +58 -0
- data/spec/jdt/manifest/library_manifest_spec.rb +17 -0
- data/spec/jdt/manifest/manifest_spec.rb +68 -0
- data/spec/jdt/manifest/referenced_spec.rb +28 -0
- data/spec/jdt/manifest/secure_spec.rb +42 -0
- data/spec/jdt/manifest/validation_spec.rb +45 -0
- data/spec/jdt/version_spec.rb +9 -0
- metadata +211 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module Jdt
|
4
|
+
|
5
|
+
class Manifest
|
6
|
+
|
7
|
+
def secure
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class IndexCreater
|
14
|
+
include Thor::Actions
|
15
|
+
|
16
|
+
def initialize (path)
|
17
|
+
@path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_index
|
21
|
+
create_index_recursive(@path)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_index_recursive (path)
|
27
|
+
template('/templates/component/index.html.erb', "#{path}/index.html")
|
28
|
+
Dir.chdir("#{path}") do
|
29
|
+
Dir.glob("*").each do |dir|
|
30
|
+
if File.directory?(dir)
|
31
|
+
create_index_recursive("#{path}/#{dir}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
module Jdt
|
4
|
+
|
5
|
+
class Manifest
|
6
|
+
|
7
|
+
attr_accessor :errors, :warnings
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
syntax_valid? and semantics_valid?
|
11
|
+
end
|
12
|
+
|
13
|
+
def errors
|
14
|
+
if(not @errors)
|
15
|
+
@errors = []
|
16
|
+
end
|
17
|
+
@errors
|
18
|
+
end
|
19
|
+
|
20
|
+
def warnings
|
21
|
+
if(not @warnings)
|
22
|
+
@warnings = []
|
23
|
+
end
|
24
|
+
@warnings
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def syntax_valid?
|
30
|
+
ManifestSchemaValidator.new(self).valid?
|
31
|
+
end
|
32
|
+
|
33
|
+
def semantics_valid?
|
34
|
+
# todo change this
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
class ManifestSchemaValidator
|
41
|
+
|
42
|
+
SCHEMAS_FOLDER = "#{File.dirname(__FILE__)}/schemas"
|
43
|
+
|
44
|
+
SCHEMAS = {:manifest => "#{SCHEMAS_FOLDER}/manifest.xsd",
|
45
|
+
:library => "#{SCHEMAS_FOLDER}/library.xsd",
|
46
|
+
:plugin => "#{SCHEMAS_FOLDER}/plugin.xsd",
|
47
|
+
:module => "#{SCHEMAS_FOLDER}/module.xsd",
|
48
|
+
:component => "#{SCHEMAS_FOLDER}/component.xsd",
|
49
|
+
:template => "#{SCHEMAS_FOLDER}/template.xsd",
|
50
|
+
:language => "#{SCHEMAS_FOLDER}/language.xsd",
|
51
|
+
:package => "#{SCHEMAS_FOLDER}/package.xsd"}
|
52
|
+
|
53
|
+
attr_accessor :manifest
|
54
|
+
|
55
|
+
def initialize(manifest)
|
56
|
+
@manifest = manifest
|
57
|
+
end
|
58
|
+
|
59
|
+
def valid?
|
60
|
+
validate_manifest and validate_specific
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def validate_manifest
|
66
|
+
validate_against_schema(SCHEMAS[:manifest])
|
67
|
+
end
|
68
|
+
|
69
|
+
def validate_specific
|
70
|
+
validate_against_schema(SCHEMAS[manifest.ext_type.to_sym])
|
71
|
+
end
|
72
|
+
|
73
|
+
def validate_against_schema(schema)
|
74
|
+
xsd = Nokogiri::XML::Schema(File.read(schema))
|
75
|
+
|
76
|
+
xsd.validate(manifest.doc).each do |error|
|
77
|
+
@manifest.errors << error.message
|
78
|
+
end
|
79
|
+
|
80
|
+
@manifest.errors.empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
class ManifestValidator
|
86
|
+
|
87
|
+
attr_accessor :manifest
|
88
|
+
|
89
|
+
def initialize(manifest)
|
90
|
+
@manifest = manifest
|
91
|
+
end
|
92
|
+
|
93
|
+
# Validates the manifest
|
94
|
+
#
|
95
|
+
# @return bool true if valid, false otherwise
|
96
|
+
def valid?
|
97
|
+
|
98
|
+
# ERROR when specified files and folders do not exist
|
99
|
+
|
100
|
+
# ERROR when optional metadata field is missing (version, author, ...)
|
101
|
+
# WARNING when metadata is missing
|
102
|
+
|
103
|
+
# evaluate the validation result
|
104
|
+
@manifest.errors.empty?
|
105
|
+
end
|
106
|
+
|
107
|
+
def validate_file_existence(file)
|
108
|
+
if (not File.exist?(file))
|
109
|
+
manifest.errors << "File #{file} does not exist, but should"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def validate_directory_existence(dir)
|
114
|
+
if (not Dir.exist?(file))
|
115
|
+
manifest.errors << "File #{file} does not exist, but should"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
2
|
+
<xsl:output method="xml" encoding="ISO-8859-1"/>
|
3
|
+
<xsl:param name="indent-increment" select="' '"/>
|
4
|
+
|
5
|
+
<xsl:template name="newline">
|
6
|
+
<xsl:text disable-output-escaping="yes">
|
7
|
+
</xsl:text>
|
8
|
+
</xsl:template>
|
9
|
+
|
10
|
+
<xsl:template match="comment() | processing-instruction()">
|
11
|
+
<xsl:param name="indent" select="''"/>
|
12
|
+
<xsl:call-template name="newline"/>
|
13
|
+
<xsl:value-of select="$indent"/>
|
14
|
+
<xsl:copy/>
|
15
|
+
</xsl:template>
|
16
|
+
|
17
|
+
<xsl:template match="text()">
|
18
|
+
<xsl:param name="indent" select="''"/>
|
19
|
+
<xsl:call-template name="newline"/>
|
20
|
+
<xsl:value-of select="$indent"/>
|
21
|
+
<xsl:value-of select="normalize-space(.)"/>
|
22
|
+
</xsl:template>
|
23
|
+
|
24
|
+
<xsl:template match="text()[normalize-space(.)='']"/>
|
25
|
+
|
26
|
+
<xsl:template match="*">
|
27
|
+
<xsl:param name="indent" select="''"/>
|
28
|
+
<xsl:call-template name="newline"/>
|
29
|
+
<xsl:value-of select="$indent"/>
|
30
|
+
<xsl:choose>
|
31
|
+
<xsl:when test="count(child::*) > 0">
|
32
|
+
<xsl:copy>
|
33
|
+
<xsl:copy-of select="@*"/>
|
34
|
+
<xsl:apply-templates select="*|text()">
|
35
|
+
<xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
|
36
|
+
</xsl:apply-templates>
|
37
|
+
<xsl:call-template name="newline"/>
|
38
|
+
<xsl:value-of select="$indent"/>
|
39
|
+
</xsl:copy>
|
40
|
+
</xsl:when>
|
41
|
+
<xsl:otherwise>
|
42
|
+
<xsl:copy-of select="."/>
|
43
|
+
</xsl:otherwise>
|
44
|
+
</xsl:choose>
|
45
|
+
</xsl:template>
|
46
|
+
</xsl:stylesheet>
|
data/lib/jdt/manifest.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require "jdt/manifest/attributes"
|
2
|
+
require "jdt/manifest/build"
|
3
|
+
require "jdt/manifest/bump"
|
4
|
+
require "jdt/manifest/find"
|
5
|
+
require "jdt/manifest/library_manifest"
|
6
|
+
require "jdt/manifest/manifest"
|
7
|
+
require "jdt/manifest/referenced"
|
8
|
+
require "jdt/manifest/secure"
|
9
|
+
require "jdt/manifest/validation"
|
data/lib/jdt/version.rb
ADDED
data/lib/jdt.rb
ADDED
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'mechanize'
|
4
|
+
|
5
|
+
HOMEPAGE = "http://127.0.0.1/joomla"
|
6
|
+
ADMIN = "#{HOMEPAGE}/administrator"
|
7
|
+
INSTALLER = "#{ADMIN}/index.php?option=com_installer"
|
8
|
+
|
9
|
+
agent = Mechanize.new
|
10
|
+
|
11
|
+
joomla_admin_page = agent.get("#{ADMIN}")
|
12
|
+
|
13
|
+
# puts joomla_admin_page.forms.first.inspect
|
14
|
+
login_form = joomla_admin_page.forms.first
|
15
|
+
login_form.field_with(:name => "username").value = "admin"
|
16
|
+
login_form.field_with(:name => "passwd").value = "spec"
|
17
|
+
|
18
|
+
logged_in_admin_page = agent.submit(login_form)
|
19
|
+
joomla_install_page = agent.get("#{INSTALLER}")
|
20
|
+
|
21
|
+
puts joomla_install_page.body
|
22
|
+
|
23
|
+
install_form = joomla_install_page.forms.first
|
24
|
+
puts install_form.inspect
|
25
|
+
puts install_form.file_uploads.first.file_name = "com_hello.zip"
|
26
|
+
|
27
|
+
installed_feedback = agent.submit(install_form)
|
28
|
+
|
29
|
+
pp installed_feedback
|
30
|
+
puts installed_feedback.body
|
31
|
+
|
32
|
+
|
33
|
+
# check if retrieved page exists
|
34
|
+
# check if retrieved page is joomla page
|
35
|
+
# check if correct form is presented
|
36
|
+
# all required fields are available
|
37
|
+
|
38
|
+
# login and check if the log in worked
|
39
|
+
# show error message in case of error
|
40
|
+
|
41
|
+
# submit install form
|
42
|
+
# get output of installation and output it on the console
|
43
|
+
# in case of error, mark it as such and give output
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
# uninstall
|
50
|
+
|
51
|
+
|
52
|
+
# sync locally
|
53
|
+
# module, plugin, template, library -> simple, only copy to directory
|
54
|
+
# component -> complex
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
class Xampp < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
desc "configure","configure server settings"
|
7
|
+
def configure
|
8
|
+
|
9
|
+
# TODO change to extension root directory
|
10
|
+
config_file = ".jdt/config.xml"
|
11
|
+
|
12
|
+
if(!File.exists?(config_file))
|
13
|
+
# create config file
|
14
|
+
create_file(config_file,"configuration file")
|
15
|
+
end
|
16
|
+
|
17
|
+
# get xampp path
|
18
|
+
# TODO what is returned when nothing is entered
|
19
|
+
xampp_path = ask("Enter fully qualified xampp path (default: C:\\xampp):")
|
20
|
+
|
21
|
+
# set xampp path default value if it has not been set
|
22
|
+
if(xampp_path == "")
|
23
|
+
xampp_path = "c:\\xampp"
|
24
|
+
end
|
25
|
+
|
26
|
+
# store information
|
27
|
+
file = File.open(config_file,"rw")
|
28
|
+
Nokogiri::XML(file)
|
29
|
+
|
30
|
+
file.close
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
"xampp_path: #{xampp_path}"
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
desc "start_server","start apache and mysql server"
|
40
|
+
def start_server
|
41
|
+
system("cd #{Config::PATH}")
|
42
|
+
system("#{Config::PATH}/apache_start.bat")
|
43
|
+
system("#{Config::PATH}/mysql_start.bat")
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "stop_server", "stops apache and mysql server"
|
47
|
+
def stop_server
|
48
|
+
system("#{Config::PATH}/apache_stop.bat")
|
49
|
+
system("#{Config::PATH}/mysql_stop.bat")
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "restart","restart apache and mysql server"
|
53
|
+
def restart
|
54
|
+
stop_server
|
55
|
+
start_server
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "php_ini","show php.ini"
|
59
|
+
def php_ini
|
60
|
+
File.open("#{Config::PATH}/php/php.ini").each_line do |line|
|
61
|
+
puts line
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "path","show path to xampp"
|
66
|
+
def path
|
67
|
+
puts "Path is #{Config::PATH}"
|
68
|
+
end
|
69
|
+
|
70
|
+
=begin
|
71
|
+
desc "phpmyadmin","open phpmyadmin in browser"
|
72
|
+
def phpmyadmin
|
73
|
+
system("#{Config::BROWSER} http://localhost/phpMyAdmin")
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "web","open web in browser"
|
77
|
+
def web
|
78
|
+
system("#{Config::BROWSER} http://localhost/")
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "tmpdir"
|
3
|
+
|
4
|
+
|
5
|
+
require "jdt/generator"
|
6
|
+
|
7
|
+
describe Jdt::LibraryGenerator do
|
8
|
+
|
9
|
+
it "should do generate a library" do
|
10
|
+
|
11
|
+
generator = Jdt::LibraryGenerator.new("test")
|
12
|
+
generator.type.should eq("library")
|
13
|
+
generator.type_short.should eq("lib")
|
14
|
+
generator.name.should eq("test")
|
15
|
+
generator.prefixed_name.should eq("lib_test")
|
16
|
+
generator.folder.should eq("./lib_test")
|
17
|
+
|
18
|
+
Dir.tmpdir do |dir|
|
19
|
+
|
20
|
+
generator.location = dir
|
21
|
+
generator.folder.should eq("#{dir}/lib_test")
|
22
|
+
|
23
|
+
generator.generate
|
24
|
+
|
25
|
+
File.exists?("#{dir}/lib_test/manifest.xml").should eq(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe Jdt::ComponentGenerator do
|
32
|
+
|
33
|
+
it "should generate a component" do
|
34
|
+
|
35
|
+
generator = Jdt::ComponentGenerator.new("test")
|
36
|
+
generator.type.should eq("component")
|
37
|
+
generator.type_short.should eq("com")
|
38
|
+
generator.name.should eq("test")
|
39
|
+
generator.prefixed_name.should eq("com_test")
|
40
|
+
generator.folder.should eq("./com_test")
|
41
|
+
|
42
|
+
Dir.tmpdir do |dir|
|
43
|
+
|
44
|
+
generator.location = dir
|
45
|
+
generator.folder.should eq("#{dir}/com_test")
|
46
|
+
|
47
|
+
generator.generate
|
48
|
+
|
49
|
+
File.exists?("#{dir}/com_test/manifest.xml").should eq(true)
|
50
|
+
File.directory?("#{dir}/com_test/site").should eq(true)
|
51
|
+
File.directory?("#{dir}/com_test/admin").should eq(true)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
/zip/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<?php
|
2
|
+
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
|
3
|
+
die('PHP ActiveRecord requires PHP 5.3 or higher');
|
4
|
+
|
5
|
+
define('PHP_ACTIVERECORD_VERSION_ID', '1.0');
|
6
|
+
|
7
|
+
require 'dist/lib/Singleton.php';
|
8
|
+
require 'dist/lib/Config.php';
|
9
|
+
require 'dist/lib/Utils.php';
|
10
|
+
require 'dist/lib/DateTime.php';
|
11
|
+
require 'dist/lib/Model.php';
|
12
|
+
require 'dist/lib/Table.php';
|
13
|
+
require 'dist/lib/ConnectionManager.php';
|
14
|
+
require 'dist/lib/Connection.php';
|
15
|
+
require 'dist/lib/SQLBuilder.php';
|
16
|
+
require 'dist/lib/Reflections.php';
|
17
|
+
require 'dist/lib/Inflector.php';
|
18
|
+
require 'dist/lib/CallBack.php';
|
19
|
+
require 'dist/lib/Exceptions.php';
|
20
|
+
require 'JoomlaConfig.php';
|
21
|
+
|
22
|
+
spl_autoload_register('activerecord_autoload');
|
23
|
+
|
24
|
+
function activerecord_autoload($class_name)
|
25
|
+
{
|
26
|
+
// iterate over all directories and search within each of them
|
27
|
+
$paths = ActiveRecord\JoomlaConfig::instance()->get_model_directories();
|
28
|
+
|
29
|
+
foreach ($paths as $path) {
|
30
|
+
$root = realpath(isset($path) ? $path : '.');
|
31
|
+
|
32
|
+
if (($namespaces = ActiveRecord\get_namespaces($class_name))) {
|
33
|
+
$class_name = array_pop($namespaces);
|
34
|
+
$directories = array();
|
35
|
+
|
36
|
+
foreach ($namespaces as $directory)
|
37
|
+
$directories[] = $directory;
|
38
|
+
|
39
|
+
$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
|
40
|
+
}
|
41
|
+
|
42
|
+
$file = "$root/$class_name.php";
|
43
|
+
|
44
|
+
if (file_exists($file)) {
|
45
|
+
require $file;
|
46
|
+
|
47
|
+
// cancel function as file has been found
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
}
|
55
|
+
|
56
|
+
?>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace ActiveRecord;
|
4
|
+
|
5
|
+
class JoomlaConfig extends Config
|
6
|
+
{
|
7
|
+
|
8
|
+
private $model_directories = array();
|
9
|
+
|
10
|
+
public function set_model_directory($dir)
|
11
|
+
{
|
12
|
+
parent::set_model_directory($dir);
|
13
|
+
|
14
|
+
// add model path to array of model paths
|
15
|
+
array_push($this->model_directories, $dir);
|
16
|
+
}
|
17
|
+
|
18
|
+
|
19
|
+
public function get_model_directories()
|
20
|
+
{
|
21
|
+
return $this->model_directories;
|
22
|
+
}
|
23
|
+
|
24
|
+
public function set_joomla_connection($connection_type = "production")
|
25
|
+
{
|
26
|
+
// get config from Joomla
|
27
|
+
$config = new JConfig();
|
28
|
+
|
29
|
+
// extract values from Joomla
|
30
|
+
$username = $config->user;
|
31
|
+
$password = $config->password;
|
32
|
+
$host = $config->host;
|
33
|
+
$database = $config->db;
|
34
|
+
|
35
|
+
// compute connection string for ActiveRecord
|
36
|
+
$connection = "mysql://$username:$password@$host/$database";
|
37
|
+
|
38
|
+
// set connection string
|
39
|
+
$this->set_connections(array($connection_type => $connection));
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Joomla Library of PHP ActiveRecord
|
2
|
+
|
3
|
+
This project enwraps the PHP ActiveRecord 1.0 within a Joomla 1.7 Library for easy usage within the CMS Joomla!
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
### Plain PHP ActiveRecord
|
8
|
+
|
9
|
+
If you want to use the plain ActiveRecord implementation, you have to import them using
|
10
|
+
|
11
|
+
jimport('activerecord.ActiveRecord');
|
12
|
+
|
13
|
+
Then, you can use them directly by following the documentation of PHP ActiveRecord.
|
14
|
+
|
15
|
+
### Enhanced PHP ActiveRecord (especially for Joomla!)
|
16
|
+
|
17
|
+
There are some additions and special constructs available for Joomla! components that easens the development. A list of them is stated below:
|
18
|
+
|
19
|
+
* ActiveRecord can automatically obtain the database credentials and configure itself using the standard Joomla! database
|
20
|
+
* Multiple model directories are supported so that every component, module, etc. can use the same ActiveRecord instance but different model locations to ensure encapsulation without performance issues.
|
21
|
+
|
22
|
+
To load JoomlaActiveRecord in your Joomla Component, just leverage this line:
|
23
|
+
|
24
|
+
jimport('activerecord.JoomlaActiveRecord');
|
25
|
+
|
26
|
+
Then, you can use the additional functionality within the configuration:
|
27
|
+
|
28
|
+
ActiveRecord\JoomlaConfig::initialize(function($cfg){
|
29
|
+
// multiple directories are also supported
|
30
|
+
$cfg->set_model_directory(JPATH_COMPONENT_ADMINISTRATOR . '/domain/.');
|
31
|
+
$cfg->set_model_directory(JPATH_COMPONENT . '/domain/.');
|
32
|
+
|
33
|
+
// uses the database connection from the Joomla configuration
|
34
|
+
$cfg->set_joomla_connection('development');
|
35
|
+
});
|
36
|
+
|
37
|
+
Please note: The configuration is a singleton. Thus, each plugin, module and component can initialize the configuration on its own and this will not result into a performance issue.
|
38
|
+
|
39
|
+
Additionally, you can call the function set_model_directory for every directory you want to add to the data mapper!
|
40
|
+
|
41
|
+
Notes:
|
42
|
+
* If you use namespaces, you can prevent a auto class loading issue.
|
43
|
+
*
|
44
|
+
|
45
|
+
## PHP ActiveRecord
|
46
|
+
|
47
|
+
PHP ActiveRecord is a PHP implementation of the famous ActiveRecord data pattern. More information can be found on the following links:
|
48
|
+
|
49
|
+
* The official homepage of PHP ActiveRecord: [[http://www.phpactiverecord.org/]]
|
50
|
+
* The github project of PHP ActiveRecord: [[https://github.com/kla/php-activerecord]]
|
51
|
+
* Explanation of the ActiveRecord pattern: [[http://en.wikipedia.org/wiki/Active_record_pattern]]
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<extension method="upgrade" type="library" version="1.7.0">
|
3
|
+
|
4
|
+
<name>activerecord</name>
|
5
|
+
<libraryname>activerecord</libraryname>
|
6
|
+
|
7
|
+
<version>2.1.1</version>
|
8
|
+
<creationDate>August 2011</creationDate>
|
9
|
+
<homepage>https://www.github.com/simonharrer/activerecord</homepage>
|
10
|
+
|
11
|
+
<author>Simon Harrer</author>
|
12
|
+
<authorEmail>simon.harrer@feki.de</authorEmail>
|
13
|
+
<authorUrl>http://www.feki.de</authorUrl>
|
14
|
+
|
15
|
+
<files>
|
16
|
+
<filename>JoomlaConfig.php</filename>
|
17
|
+
<filename>JoomlaActiveRecord.php</filename>
|
18
|
+
<filename>README.md</filename>
|
19
|
+
<folder>dist</folder>
|
20
|
+
</files>
|
21
|
+
|
22
|
+
</extension>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<extension type="library" version="1.7.0" method="upgrade">
|
3
|
+
|
4
|
+
<name>activerecord</name>
|
5
|
+
<description>desc text</description>
|
6
|
+
<libraryname>activerecord</libraryname>
|
7
|
+
|
8
|
+
<version>1.0.0</version>
|
9
|
+
<creationDate>August 2011</creationDate>
|
10
|
+
<homepage>https://www.github.com/simonharrer/activerecord</homepage>
|
11
|
+
|
12
|
+
<author>Simon Harrer</author>
|
13
|
+
<authorEmail>simon.harrer@feki.de</authorEmail>
|
14
|
+
<authorUrl>http://www.feki.de</authorUrl>
|
15
|
+
|
16
|
+
<license>licsence text</license>
|
17
|
+
<copyright>copyright text</copyright>
|
18
|
+
|
19
|
+
<files>
|
20
|
+
<filename>JoomlaConfig.php</filename>
|
21
|
+
<filename>JoomlaActiveRecord.php</filename>
|
22
|
+
<filename>README.md</filename>
|
23
|
+
<folder>dist</folder>
|
24
|
+
</files>
|
25
|
+
|
26
|
+
<scriptfile>example.script.php</scriptfile>
|
27
|
+
|
28
|
+
<updateservers>
|
29
|
+
<server type="extension" priority="1" name="Extension Update Site">http://example.com/extension.xml</server>
|
30
|
+
<server type="collection" priority="2" name="Collection Update Site">http://example.com/collection.xml</server>
|
31
|
+
</updateservers>
|
32
|
+
|
33
|
+
</extension>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<extension type="library" version="1.7.0" method="upgrade">
|
3
|
+
|
4
|
+
<name>activerecord</name>
|
5
|
+
|
6
|
+
<version>1.0</version>
|
7
|
+
<creationDate>August 2011</creationDate>
|
8
|
+
<homepage>https://www.github.com/simonharrer/activerecord</homepage>
|
9
|
+
|
10
|
+
<author>Simon Harrer</author>
|
11
|
+
<authorEmail>simon.harrer@feki.de</authorEmail>
|
12
|
+
<authorUrl>http://www.feki.de</authorUrl>
|
13
|
+
|
14
|
+
<test>asdf</test>
|
15
|
+
|
16
|
+
<scriptfile>example.script.php</scriptfile>
|
17
|
+
|
18
|
+
<updateservers>
|
19
|
+
<server type="extension" priority="1" name="Extension Update Site">http://example.com/extension.xml</server>
|
20
|
+
<server type="collection" priority="2" name="Collection Update Site">http://example.com/collection.xml</server>
|
21
|
+
</updateservers>
|
22
|
+
|
23
|
+
</extension>
|