PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 1ms

/yii/framework/base/interfaces.php

https://github.com/joshuaswarren/weatherhub
PHP | 609 lines | 102 code | 29 blank | 478 comment | 0 complexity | 54eea60703d87d1d4f0b904e641845bb MD5 | raw file
  1. <?php
  2. /**
  3. * This file contains core interfaces for Yii framework.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright Copyright &copy; 2008-2011 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * IApplicationComponent is the interface that all application components must implement.
  12. *
  13. * After the application completes configuration, it will invoke the {@link init()}
  14. * method of every loaded application component.
  15. *
  16. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  18. * @package system.base
  19. * @since 1.0
  20. */
  21. interface IApplicationComponent
  22. {
  23. /**
  24. * Initializes the application component.
  25. * This method is invoked after the application completes configuration.
  26. */
  27. public function init();
  28. /**
  29. * @return boolean whether the {@link init()} method has been invoked.
  30. */
  31. public function getIsInitialized();
  32. }
  33. /**
  34. * ICache is the interface that must be implemented by cache components.
  35. *
  36. * This interface must be implemented by classes supporting caching feature.
  37. *
  38. * @author Qiang Xue <qiang.xue@gmail.com>
  39. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  40. * @package system.caching
  41. * @since 1.0
  42. */
  43. interface ICache
  44. {
  45. /**
  46. * Retrieves a value from cache with a specified key.
  47. * @param string $id a key identifying the cached value
  48. * @return mixed the value stored in cache, false if the value is not in the cache or expired.
  49. */
  50. public function get($id);
  51. /**
  52. * Retrieves multiple values from cache with the specified keys.
  53. * Some caches (such as memcache, apc) allow retrieving multiple cached values at one time,
  54. * which may improve the performance since it reduces the communication cost.
  55. * In case a cache doesn't support this feature natively, it will be simulated by this method.
  56. * @param array $ids list of keys identifying the cached values
  57. * @return array list of cached values corresponding to the specified keys. The array
  58. * is returned in terms of (key,value) pairs.
  59. * If a value is not cached or expired, the corresponding array value will be false.
  60. * @since 1.0.8
  61. */
  62. public function mget($ids);
  63. /**
  64. * Stores a value identified by a key into cache.
  65. * If the cache already contains such a key, the existing value and
  66. * expiration time will be replaced with the new ones.
  67. *
  68. * @param string $id the key identifying the value to be cached
  69. * @param mixed $value the value to be cached
  70. * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
  71. * @param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
  72. * @return boolean true if the value is successfully stored into cache, false otherwise
  73. */
  74. public function set($id,$value,$expire=0,$dependency=null);
  75. /**
  76. * Stores a value identified by a key into cache if the cache does not contain this key.
  77. * Nothing will be done if the cache already contains the key.
  78. * @param string $id the key identifying the value to be cached
  79. * @param mixed $value the value to be cached
  80. * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
  81. * @param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
  82. * @return boolean true if the value is successfully stored into cache, false otherwise
  83. */
  84. public function add($id,$value,$expire=0,$dependency=null);
  85. /**
  86. * Deletes a value with the specified key from cache
  87. * @param string $id the key of the value to be deleted
  88. * @return boolean whether the deletion is successful
  89. */
  90. public function delete($id);
  91. /**
  92. * Deletes all values from cache.
  93. * Be careful of performing this operation if the cache is shared by multiple applications.
  94. * @return boolean whether the flush operation was successful.
  95. */
  96. public function flush();
  97. }
  98. /**
  99. * ICacheDependency is the interface that must be implemented by cache dependency classes.
  100. *
  101. * This interface must be implemented by classes meant to be used as
  102. * cache dependencies.
  103. *
  104. * Objects implementing this interface must be able to be serialized and unserialized.
  105. *
  106. * @author Qiang Xue <qiang.xue@gmail.com>
  107. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  108. * @package system.caching
  109. * @since 1.0
  110. */
  111. interface ICacheDependency
  112. {
  113. /**
  114. * Evaluates the dependency by generating and saving the data related with dependency.
  115. * This method is invoked by cache before writing data into it.
  116. */
  117. public function evaluateDependency();
  118. /**
  119. * @return boolean whether the dependency has changed.
  120. */
  121. public function getHasChanged();
  122. }
  123. /**
  124. * IStatePersister is the interface that must be implemented by state persister calsses.
  125. *
  126. * This interface must be implemented by all state persister classes (such as
  127. * {@link CStatePersister}.
  128. *
  129. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  130. * @package system.base
  131. * @since 1.0
  132. */
  133. interface IStatePersister
  134. {
  135. /**
  136. * Loads state data from a persistent storage.
  137. * @return mixed the state
  138. */
  139. public function load();
  140. /**
  141. * Saves state data into a persistent storage.
  142. * @param mixed $state the state to be saved
  143. */
  144. public function save($state);
  145. }
  146. /**
  147. * IFilter is the interface that must be implemented by action filters.
  148. *
  149. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  150. * @package system.base
  151. * @since 1.0
  152. */
  153. interface IFilter
  154. {
  155. /**
  156. * Performs the filtering.
  157. * This method should be implemented to perform actual filtering.
  158. * If the filter wants to continue the action execution, it should call
  159. * <code>$filterChain->run()</code>.
  160. * @param CFilterChain $filterChain the filter chain that the filter is on.
  161. */
  162. public function filter($filterChain);
  163. }
  164. /**
  165. * IAction is the interface that must be implemented by controller actions.
  166. *
  167. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  168. * @package system.base
  169. * @since 1.0
  170. */
  171. interface IAction
  172. {
  173. /**
  174. * @return string id of the action
  175. */
  176. public function getId();
  177. /**
  178. * @return CController the controller instance
  179. */
  180. public function getController();
  181. }
  182. /**
  183. * IWebServiceProvider interface may be implemented by Web service provider classes.
  184. *
  185. * If this interface is implemented, the provider instance will be able
  186. * to intercept the remote method invocation (e.g. for logging or authentication purpose).
  187. * @author Qiang Xue <qiang.xue@gmail.com>
  188. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  189. * @package system.base
  190. * @since 1.0
  191. */
  192. interface IWebServiceProvider
  193. {
  194. /**
  195. * This method is invoked before the requested remote method is invoked.
  196. * @param CWebService $service the currently requested Web service.
  197. * @return boolean whether the remote method should be executed.
  198. */
  199. public function beforeWebMethod($service);
  200. /**
  201. * This method is invoked after the requested remote method is invoked.
  202. * @param CWebService $service the currently requested Web service.
  203. */
  204. public function afterWebMethod($service);
  205. }
  206. /**
  207. * IViewRenderer interface is implemented by a view renderer class.
  208. *
  209. * A view renderer is {@link CWebApplication::viewRenderer viewRenderer}
  210. * application component whose wants to replace the default view rendering logic
  211. * implemented in {@link CBaseController}.
  212. *
  213. * @author Qiang Xue <qiang.xue@gmail.com>
  214. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  215. * @package system.base
  216. * @since 1.0
  217. */
  218. interface IViewRenderer
  219. {
  220. /**
  221. * Renders a view file.
  222. * @param CBaseController $context the controller or widget who is rendering the view file.
  223. * @param string $file the view file path
  224. * @param mixed $data the data to be passed to the view
  225. * @param boolean $return whether the rendering result should be returned
  226. * @return mixed the rendering result, or null if the rendering result is not needed.
  227. */
  228. public function renderFile($context,$file,$data,$return);
  229. }
  230. /**
  231. * IUserIdentity interface is implemented by a user identity class.
  232. *
  233. * An identity represents a way to authenticate a user and retrieve
  234. * information needed to uniquely identity the user. It is normally
  235. * used with the {@link CWebApplication::user user application component}.
  236. *
  237. * @author Qiang Xue <qiang.xue@gmail.com>
  238. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  239. * @package system.base
  240. * @since 1.0
  241. */
  242. interface IUserIdentity
  243. {
  244. /**
  245. * Authenticates the user.
  246. * The information needed to authenticate the user
  247. * are usually provided in the constructor.
  248. * @return boolean whether authentication succeeds.
  249. */
  250. public function authenticate();
  251. /**
  252. * Returns a value indicating whether the identity is authenticated.
  253. * @return boolean whether the identity is valid.
  254. */
  255. public function getIsAuthenticated();
  256. /**
  257. * Returns a value that uniquely represents the identity.
  258. * @return mixed a value that uniquely represents the identity (e.g. primary key value).
  259. */
  260. public function getId();
  261. /**
  262. * Returns the display name for the identity (e.g. username).
  263. * @return string the display name for the identity.
  264. */
  265. public function getName();
  266. /**
  267. * Returns the additional identity information that needs to be persistent during the user session.
  268. * @return array additional identity information that needs to be persistent during the user session (excluding {@link id}).
  269. */
  270. public function getPersistentStates();
  271. }
  272. /**
  273. * IWebUser interface is implemented by a {@link CWebApplication::user user application component}.
  274. *
  275. * A user application component represents the identity information
  276. * for the current user.
  277. *
  278. * @author Qiang Xue <qiang.xue@gmail.com>
  279. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  280. * @package system.base
  281. * @since 1.0
  282. */
  283. interface IWebUser
  284. {
  285. /**
  286. * Returns a value that uniquely represents the identity.
  287. * @return mixed a value that uniquely represents the identity (e.g. primary key value).
  288. */
  289. public function getId();
  290. /**
  291. * Returns the display name for the identity (e.g. username).
  292. * @return string the display name for the identity.
  293. */
  294. public function getName();
  295. /**
  296. * Returns a value indicating whether the user is a guest (not authenticated).
  297. * @return boolean whether the user is a guest (not authenticated)
  298. */
  299. public function getIsGuest();
  300. /**
  301. * Performs access check for this user.
  302. * @param string $operation the name of the operation that need access check.
  303. * @param array $params name-value pairs that would be passed to business rules associated
  304. * with the tasks and roles assigned to the user.
  305. * @return boolean whether the operations can be performed by this user.
  306. */
  307. public function checkAccess($operation,$params=array());
  308. }
  309. /**
  310. * IAuthManager interface is implemented by an auth manager application component.
  311. *
  312. * An auth manager is mainly responsible for providing role-based access control (RBAC) service.
  313. *
  314. * @author Qiang Xue <qiang.xue@gmail.com>
  315. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  316. * @package system.base
  317. * @since 1.0
  318. */
  319. interface IAuthManager
  320. {
  321. /**
  322. * Performs access check for the specified user.
  323. * @param string $itemName the name of the operation that need access check
  324. * @param mixed $userId the user ID. This should can be either an integer and a string representing
  325. * the unique identifier of a user. See {@link IWebUser::getId}.
  326. * @param array $params name-value pairs that would be passed to biz rules associated
  327. * with the tasks and roles assigned to the user.
  328. * @return boolean whether the operations can be performed by the user.
  329. */
  330. public function checkAccess($itemName,$userId,$params=array());
  331. /**
  332. * Creates an authorization item.
  333. * An authorization item represents an action permission (e.g. creating a post).
  334. * It has three types: operation, task and role.
  335. * Authorization items form a hierarchy. Higher level items inheirt permissions representing
  336. * by lower level items.
  337. * @param string $name the item name. This must be a unique identifier.
  338. * @param integer $type the item type (0: operation, 1: task, 2: role).
  339. * @param string $description description of the item
  340. * @param string $bizRule business rule associated with the item. This is a piece of
  341. * PHP code that will be executed when {@link checkAccess} is called for the item.
  342. * @param mixed $data additional data associated with the item.
  343. * @return CAuthItem the authorization item
  344. * @throws CException if an item with the same name already exists
  345. */
  346. public function createAuthItem($name,$type,$description='',$bizRule=null,$data=null);
  347. /**
  348. * Removes the specified authorization item.
  349. * @param string $name the name of the item to be removed
  350. * @return boolean whether the item exists in the storage and has been removed
  351. */
  352. public function removeAuthItem($name);
  353. /**
  354. * Returns the authorization items of the specific type and user.
  355. * @param integer $type the item type (0: operation, 1: task, 2: role). Defaults to null,
  356. * meaning returning all items regardless of their type.
  357. * @param mixed $userId the user ID. Defaults to null, meaning returning all items even if
  358. * they are not assigned to a user.
  359. * @return array the authorization items of the specific type.
  360. */
  361. public function getAuthItems($type=null,$userId=null);
  362. /**
  363. * Returns the authorization item with the specified name.
  364. * @param string $name the name of the item
  365. * @return CAuthItem the authorization item. Null if the item cannot be found.
  366. */
  367. public function getAuthItem($name);
  368. /**
  369. * Saves an authorization item to persistent storage.
  370. * @param CAuthItem $item the item to be saved.
  371. * @param string $oldName the old item name. If null, it means the item name is not changed.
  372. */
  373. public function saveAuthItem($item,$oldName=null);
  374. /**
  375. * Adds an item as a child of another item.
  376. * @param string $itemName the parent item name
  377. * @param string $childName the child item name
  378. * @throws CException if either parent or child doesn't exist or if a loop has been detected.
  379. */
  380. public function addItemChild($itemName,$childName);
  381. /**
  382. * Removes a child from its parent.
  383. * Note, the child item is not deleted. Only the parent-child relationship is removed.
  384. * @param string $itemName the parent item name
  385. * @param string $childName the child item name
  386. * @return boolean whether the removal is successful
  387. */
  388. public function removeItemChild($itemName,$childName);
  389. /**
  390. * Returns a value indicating whether a child exists within a parent.
  391. * @param string $itemName the parent item name
  392. * @param string $childName the child item name
  393. * @return boolean whether the child exists
  394. */
  395. public function hasItemChild($itemName,$childName);
  396. /**
  397. * Returns the children of the specified item.
  398. * @param mixed $itemName the parent item name. This can be either a string or an array.
  399. * The latter represents a list of item names (available since version 1.0.5).
  400. * @return array all child items of the parent
  401. */
  402. public function getItemChildren($itemName);
  403. /**
  404. * Assigns an authorization item to a user.
  405. * @param string $itemName the item name
  406. * @param mixed $userId the user ID (see {@link IWebUser::getId})
  407. * @param string $bizRule the business rule to be executed when {@link checkAccess} is called
  408. * for this particular authorization item.
  409. * @param mixed $data additional data associated with this assignment
  410. * @return CAuthAssignment the authorization assignment information.
  411. * @throws CException if the item does not exist or if the item has already been assigned to the user
  412. */
  413. public function assign($itemName,$userId,$bizRule=null,$data=null);
  414. /**
  415. * Revokes an authorization assignment from a user.
  416. * @param string $itemName the item name
  417. * @param mixed $userId the user ID (see {@link IWebUser::getId})
  418. * @return boolean whether removal is successful
  419. */
  420. public function revoke($itemName,$userId);
  421. /**
  422. * Returns a value indicating whether the item has been assigned to the user.
  423. * @param string $itemName the item name
  424. * @param mixed $userId the user ID (see {@link IWebUser::getId})
  425. * @return boolean whether the item has been assigned to the user.
  426. */
  427. public function isAssigned($itemName,$userId);
  428. /**
  429. * Returns the item assignment information.
  430. * @param string $itemName the item name
  431. * @param mixed $userId the user ID (see {@link IWebUser::getId})
  432. * @return CAuthAssignment the item assignment information. Null is returned if
  433. * the item is not assigned to the user.
  434. */
  435. public function getAuthAssignment($itemName,$userId);
  436. /**
  437. * Returns the item assignments for the specified user.
  438. * @param mixed $userId the user ID (see {@link IWebUser::getId})
  439. * @return array the item assignment information for the user. An empty array will be
  440. * returned if there is no item assigned to the user.
  441. */
  442. public function getAuthAssignments($userId);
  443. /**
  444. * Saves the changes to an authorization assignment.
  445. * @param CAuthAssignment $assignment the assignment that has been changed.
  446. */
  447. public function saveAuthAssignment($assignment);
  448. /**
  449. * Removes all authorization data.
  450. */
  451. public function clearAll();
  452. /**
  453. * Removes all authorization assignments.
  454. */
  455. public function clearAuthAssignments();
  456. /**
  457. * Saves authorization data into persistent storage.
  458. * If any change is made to the authorization data, please make
  459. * sure you call this method to save the changed data into persistent storage.
  460. */
  461. public function save();
  462. /**
  463. * Executes a business rule.
  464. * A business rule is a piece of PHP code that will be executed when {@link checkAccess} is called.
  465. * @param string $bizRule the business rule to be executed.
  466. * @param array $params additional parameters to be passed to the business rule when being executed.
  467. * @param mixed $data additional data that is associated with the corresponding authorization item or assignment
  468. * @return whether the execution returns a true value.
  469. * If the business rule is empty, it will also return true.
  470. */
  471. public function executeBizRule($bizRule,$params,$data);
  472. }
  473. /**
  474. * IBehavior interfaces is implemented by all behavior classes.
  475. *
  476. * A behavior is a way to enhance a component with additional methods that
  477. * are defined in the behavior class and not available in the component class.
  478. *
  479. * @author Qiang Xue <qiang.xue@gmail.com>
  480. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  481. * @package system.base
  482. * @since 1.0.2
  483. */
  484. interface IBehavior
  485. {
  486. /**
  487. * Attaches the behavior object to the component.
  488. * @param CComponent $component the component that this behavior is to be attached to.
  489. */
  490. public function attach($component);
  491. /**
  492. * Detaches the behavior object from the component.
  493. * @param CComponent $component the component that this behavior is to be detached from.
  494. */
  495. public function detach($component);
  496. /**
  497. * @return boolean whether this behavior is enabled
  498. */
  499. public function getEnabled();
  500. /**
  501. * @param boolean $value whether this behavior is enabled
  502. */
  503. public function setEnabled($value);
  504. }
  505. /**
  506. * IWidgetFactory is the interface that must be implemented by a widget factory class.
  507. *
  508. * When calling {@link CBaseController::createWidget}, if a widget factory is available,
  509. * it will be used for creating the requested widget.
  510. *
  511. * @author Qiang Xue <qiang.xue@gmail.com>
  512. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  513. * @package system.web
  514. * @since 1.1
  515. */
  516. interface IWidgetFactory
  517. {
  518. /**
  519. * Creates a new widget based on the given class name and initial properties.
  520. * @param CBaseController $owner the owner of the new widget
  521. * @param string $className the class name of the widget. This can also be a path alias (e.g. system.web.widgets.COutputCache)
  522. * @param array $properties the initial property values (name=>value) of the widget.
  523. * @return CWidget the newly created widget whose properties have been initialized with the given values.
  524. */
  525. public function createWidget($owner,$className,$properties=array());
  526. }
  527. /**
  528. * IDataProvider is the interface that must be implemented by data provider classes.
  529. *
  530. * Data providers are components that can feed data for widgets such as data grid, data list.
  531. * Besides providing data, they also support pagination and sorting.
  532. *
  533. * @author Qiang Xue <qiang.xue@gmail.com>
  534. * @version $Id: interfaces.php 3058 2011-03-13 04:20:12Z qiang.xue $
  535. * @package system.web
  536. * @since 1.1
  537. */
  538. interface IDataProvider
  539. {
  540. /**
  541. * @return string the unique ID that identifies the data provider from other data providers.
  542. */
  543. public function getId();
  544. /**
  545. * Returns the number of data items in the current page.
  546. * This is equivalent to <code>count($provider->getData())</code>.
  547. * When {@link pagination} is set false, this returns the same value as {@link totalItemCount}.
  548. * @param boolean $refresh whether the number of data items should be re-calculated.
  549. * @return integer the number of data items in the current page.
  550. */
  551. public function getItemCount($refresh=false);
  552. /**
  553. * Returns the total number of data items.
  554. * When {@link pagination} is set false, this returns the same value as {@link itemCount}.
  555. * @param boolean $refresh whether the total number of data items should be re-calculated.
  556. * @return integer total number of possible data items.
  557. */
  558. public function getTotalItemCount($refresh=false);
  559. /**
  560. * Returns the data items currently available.
  561. * @param boolean $refresh whether the data should be re-fetched from persistent storage.
  562. * @return array the list of data items currently available in this data provider.
  563. */
  564. public function getData($refresh=false);
  565. /**
  566. * Returns the key values associated with the data items.
  567. * @param boolean $refresh whether the keys should be re-calculated.
  568. * @return array the list of key values corresponding to {@link data}. Each data item in {@link data}
  569. * is uniquely identified by the corresponding key value in this array.
  570. */
  571. public function getKeys($refresh=false);
  572. /**
  573. * @return CSort the sorting object. If this is false, it means the sorting is disabled.
  574. */
  575. public function getSort();
  576. /**
  577. * @return CPagination the pagination object. If this is false, it means the pagination is disabled.
  578. */
  579. public function getPagination();
  580. }