Skip to content

Commit e57d50d

Browse files
author
Ivan Kutuzov
committed
restructure, add license and readme
1 parent f68597b commit e57d50d

File tree

139 files changed

+2911
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+2911
-0
lines changed

LICENSE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Copyright 2012 Interkassa, Inc.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
14+
PHP version 5.3

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Model Management systems
2+
3+
Useful for building interface for control and update service's data
4+
5+
include lib/Mms to your project
6+
describe application modes as in example
7+
8+
create instace of manager (Mms_Manager) and call getInterface/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/Mms/Control.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
class Mms_Control
3+
{
4+
public static function getClass($type)
5+
{
6+
$type = Zend_Filter::filterStatic($type, 'Word_CamelCaseToUnderscore');
7+
$type = Zend_Filter::filterStatic($type, 'Word_SeparatorToCamelCase', array('-'));
8+
9+
$class = 'Mms_Control_' . ucfirst($type);
10+
if (!@class_exists($class)) {
11+
throw new Mms_Exception('Control does not exist - ' . $type);
12+
}
13+
return $class;
14+
}
15+
16+
public static function factory($type, $options = array())
17+
{
18+
$class = self::getClass($type);
19+
$instance = new $class((array) $options);
20+
if ($instance instanceof Mms_Control_Abstract) {
21+
return $instance;
22+
} else {
23+
throw new Mms_Exception('Invalid control name - ' . $type);
24+
}
25+
}
26+
}

lib/Mms/Control/Abstract.php

Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
<?php
2+
abstract class Mms_Control_Abstract
3+
{
4+
/******************************************************************************
5+
* SYSTEM
6+
******************************************************************************/
7+
8+
public function __construct($options = null)
9+
{
10+
if (!empty($options)) {
11+
if (is_array($options) || $options instanceof Zend_Config) {
12+
$this->setOptions($options);
13+
} else {
14+
throw new Exception('Invalid option provided to constructor');
15+
}
16+
}
17+
}
18+
19+
public function setOptions($options)
20+
{
21+
if (empty($options)) {
22+
return;
23+
}
24+
25+
if ($options instanceof Zend_Config) {
26+
$options = $options->toArray();
27+
} elseif (!is_array($options)) {
28+
throw new Exception('setOptions() expects either an array or a Zend_Config object');
29+
}
30+
31+
foreach ($options as $key => $value) {
32+
$method = 'set' . ucfirst($key);
33+
if ($method == 'setOptions') {
34+
continue;
35+
}
36+
if (method_exists($this, $method)) {
37+
$this->{$method}($value);
38+
}
39+
}
40+
}
41+
42+
public function getControlAlias()
43+
{
44+
$name = get_class($this);
45+
return lcfirst(substr($name, strlen('Mms_Control_')));
46+
}
47+
48+
public static function getQuerySet($request)
49+
{
50+
}
51+
52+
53+
/******************************************************************************
54+
* SPECIFICATION
55+
******************************************************************************/
56+
57+
protected $_specifications = null;
58+
59+
public function getSpecification($specification = array())
60+
{
61+
if (!empty($this->_relateControls)) {
62+
foreach ($this->_relateControls as $control) {
63+
$specification['controls'][] = $control;
64+
}
65+
}
66+
67+
if (!empty($this->_requireData)) {
68+
foreach ($this->_requireData as $alias => $need) {
69+
if ($need === false) {
70+
continue;
71+
}
72+
$specification['params'][] = $alias;
73+
}
74+
}
75+
return $specification;
76+
}
77+
78+
/******************************************************************************
79+
* VIEW
80+
******************************************************************************/
81+
82+
/**
83+
* @var Zend_View
84+
*/
85+
protected $_view;
86+
87+
protected $_template = 'default';
88+
89+
protected $_renderOutput = null;
90+
91+
public function getView()
92+
{
93+
if (empty($this->_view)) {
94+
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
95+
if (null === $viewRenderer->view) {
96+
$viewRenderer->initView();
97+
}
98+
$this->_view = $viewRenderer->view;
99+
$this->_view->addScriptPath('../lib/Mms/Control/view/');
100+
}
101+
return $this->_view;
102+
}
103+
104+
public function getViewScript($templateName ='default')
105+
{
106+
$alias = $this->getControlAlias();
107+
if ($alias == Mms_Manager::C_FORM) {
108+
$script = strtolower($alias) . '/' . $templateName . '.phtml';
109+
} else {
110+
$script = strtolower($alias) . '.phtml';
111+
}
112+
return $script;
113+
}
114+
115+
116+
public function setView($view)
117+
{
118+
$this->_view = $view;
119+
}
120+
121+
public function getTemplate()
122+
{
123+
return $this->_template;
124+
}
125+
126+
public function setTemplate($name)
127+
{
128+
$this->_template = $name;
129+
}
130+
public function render($templateName = null)
131+
{
132+
if ($this->isRendered()) {
133+
return $this->getRenderOutput();
134+
}
135+
136+
$this->_dispatch();
137+
138+
if ($templateName === null) {
139+
$templateName = $this->getTemplate();
140+
}
141+
142+
$this->_render($templateName);
143+
144+
return $this->getRenderOutput();
145+
}
146+
147+
protected function _render($templateName)
148+
{
149+
$script = $this->getViewScript($templateName);
150+
151+
$view = $this->getView();
152+
153+
$this->_renderOutput = '';
154+
155+
if (isset($this->_params['noRender']) && $this->_params['noRender'] === true) {
156+
return;
157+
}
158+
foreach ($this->_params as $alias => $value) {
159+
$view->$alias = $value;
160+
}
161+
162+
$this->_renderOutput .= $view->render($script);
163+
}
164+
165+
public function getRenderOutput()
166+
{
167+
return (string) $this->_renderOutput;
168+
}
169+
170+
public function isRendered()
171+
{
172+
return !is_null($this->_renderOutput);
173+
}
174+
175+
protected function _dispatch()
176+
{}
177+
178+
/******************************************************************************
179+
* PARAMS
180+
******************************************************************************/
181+
182+
protected $_params = array();
183+
184+
/**
185+
* @param array $params
186+
*/
187+
public function setParams(array $params)
188+
{
189+
if (is_array($this->_params)) {
190+
$this->_params = array_merge($this->_params, $params);
191+
} elseif (!empty($this->_params)) {
192+
$this->_params = array_merge($params, array($this->_params));
193+
} else {
194+
$this->_params = $params;
195+
}
196+
return $this;
197+
}
198+
199+
/**
200+
* @return mixed
201+
*/
202+
public function getParams($key = null, $default = null)
203+
{
204+
if ($key === null) {
205+
return $this->_params;
206+
} elseif (isset($this->_params[$key])) {
207+
return $this->_params[$key];
208+
}
209+
return $default;
210+
}
211+
212+
public function clearParams($name = null)
213+
{
214+
if (null === $name) {
215+
$this->_params = array();
216+
} elseif (is_string($name) && isset($this->_params[$name])) {
217+
unset($this->_params[$name]);
218+
} elseif (is_array($name)) {
219+
foreach ($name as $key) {
220+
if (is_string($key) && isset($this->_params[$key])) {
221+
unset($this->_params[$key]);
222+
}
223+
}
224+
}
225+
226+
return $this;
227+
}
228+
229+
public function hasParam($name)
230+
{
231+
return isset($this->_params[$name]);
232+
}
233+
234+
public function unsetParam($name)
235+
{
236+
unset($this->_params[$name]);
237+
}
238+
239+
/******************************************************************************
240+
* REQUIRED DATA
241+
******************************************************************************/
242+
243+
const P_DATA = 'data';
244+
const P_TITLE = 'title';
245+
const P_PARAMS = 'params';
246+
const P_METADATA = 'metadata';
247+
const P_FORM_TYPE = 'formType';
248+
const P_EXPORT_DATA = 'exportData';
249+
250+
//in specific control define keys only with true, that really need
251+
protected $_requireData = array(
252+
self::P_DATA => false,
253+
self::P_TITLE => false,
254+
self::P_PARAMS => false,
255+
self::P_METADATA => false,
256+
self::P_FORM_TYPE => false,
257+
self::P_EXPORT_DATA => false,
258+
);
259+
260+
public function getRequireData()
261+
{
262+
return $this->_requireData;
263+
}
264+
265+
public function setRequiredData($alias, $set)
266+
{
267+
$this->setParams(array($alias => $set));
268+
$this->getView()->$alias = $set;
269+
}
270+
271+
protected function _getMetadata($key)
272+
{
273+
$metadata = $this->getParams(self::P_METADATA);
274+
if (isset($metadata[$key])) {
275+
return $metadata[$key];
276+
}
277+
return null;
278+
}
279+
280+
/******************************************************************************
281+
* PREPARED
282+
******************************************************************************/
283+
284+
protected $_isPrepared = false;
285+
286+
public function isPrepared()
287+
{
288+
return $this->_isPrepared;
289+
}
290+
291+
public function setPrepared($state)
292+
{
293+
$this->_isPrepared = $state;
294+
}
295+
296+
/******************************************************************************
297+
* RELATION
298+
******************************************************************************/
299+
300+
protected $_relateControls = array();
301+
302+
public function setRelateControls($controlSet)
303+
{
304+
$newRelated = array();
305+
foreach ($controlSet as $alias => $state) {
306+
if (in_array($alias, $this->_relateControls)) {
307+
$newRelated[$alias] = $state;
308+
}
309+
}
310+
if (count($newRelated) > 0) {
311+
$this->_relateControls = $newRelated;
312+
}
313+
}
314+
315+
/******************************************************************************
316+
* REQUEST
317+
******************************************************************************/
318+
319+
/**
320+
* @var Zend_Controller_Request_Http
321+
*/
322+
protected $_request;
323+
324+
public function setRequest(Zend_Controller_Request_Http $request)
325+
{
326+
$this->_request = $request;
327+
}
328+
329+
public function getRequest()
330+
{
331+
return $this->_request;
332+
}
333+
334+
/******************************************************************************
335+
* END.
336+
******************************************************************************/
337+
338+
}

0 commit comments

Comments
 (0)