idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
30,900
public function getRow ( QueryBuilder $ qb , array $ params = [ ] , $ inDeleted = false ) { if ( $ this -> softDelete && ! $ inDeleted ) { $ qb -> andWhere ( 't.' . $ this -> softDeleteName . ' IS NULL' ) ; } return $ this -> db -> fetchAssoc ( $ qb -> getSQL ( ) , $ params ) ; }
Recupera o primeiro registro que casa com uma consulta montada no QueryBuilder .
30,901
public function find ( $ id , $ inDeleted = false ) { $ qb = $ this -> db -> createQueryBuilder ( ) ; $ qb -> select ( $ this -> getSelect ( $ this -> profile ) ) -> from ( $ this -> table , 't' ) -> where ( 't.' . $ this -> primaryKey . " = :id" ) ; $ this -> addJoins ( $ qb , $ this -> getJoins ( $ this -> profile ) ) ; $ params = $ this -> addFilters ( $ qb , $ this -> getFilters ( $ this -> profile ) ) ; $ this -> addGrouping ( $ qb , $ this -> getGroupings ( $ this -> profile ) ) ; $ params [ 'id' ] = $ id ; return $ this -> getRow ( $ qb , $ params , $ inDeleted ) ; }
Localiza um registro unico pelo seu id .
30,902
public function findOneBy ( $ filters , $ inDeleted = false ) { $ qb = $ this -> db -> createQueryBuilder ( ) ; $ qb -> select ( $ this -> getSelect ( $ this -> profile ) ) -> from ( $ this -> table , 't' ) -> where ( '1 = 1' ) ; $ this -> addJoins ( $ qb , $ this -> getJoins ( $ this -> profile ) ) ; $ params = $ this -> addFilters ( $ qb , $ this -> getFilters ( $ this -> profile ) ) ; $ params = array_merge ( $ params , $ this -> addFilters ( $ qb , $ filters ) ) ; return $ this -> getRow ( $ qb , $ params , $ inDeleted ) ; }
Localiza o primeiro registro que casa com um conjunto de filtros .
30,903
public function findBy ( $ filters , $ pageOpts = array ( ) , $ sort = array ( ) , $ inDeleted = false ) { $ qb = $ this -> db -> createQueryBuilder ( ) ; $ qb -> select ( $ this -> getSelect ( $ this -> profile ) ) -> from ( $ this -> table , 't' ) -> where ( '1 = 1' ) ; $ this -> addJoins ( $ qb , $ this -> getJoins ( $ this -> profile ) ) ; $ params = $ this -> addFilters ( $ qb , $ this -> getFilters ( $ this -> profile ) ) ; $ params = array_merge ( $ params , $ this -> addFilters ( $ qb , $ filters ) ) ; $ this -> addGrouping ( $ qb , $ this -> getGroupings ( $ this -> profile ) ) ; $ this -> addSort ( $ qb , $ sort ) ; return $ this -> getAll ( $ qb , $ params , $ pageOpts , $ inDeleted ) ; }
Localiza os registros que casam com um conjunto de filtros .
30,904
public function save ( $ data ) { if ( ! isset ( $ data [ $ this -> primaryKey ] ) ) { $ data [ $ this -> primaryKey ] = 0 ; } try { if ( 0 === $ data [ $ this -> primaryKey ] ) { unset ( $ data [ $ this -> primaryKey ] ) ; $ id = $ this -> insert ( $ data ) ; } else { if ( $ this -> find ( $ data [ $ this -> primaryKey ] , true ) ) { $ this -> update ( $ data ) ; } else { $ this -> insert ( $ data ) ; } $ id = $ data [ $ this -> primaryKey ] ; } } catch ( \ Exception $ e ) { return [ 'code' => $ e -> getCode ( ) , 'message' => $ e -> getMessage ( ) ] ; } return $ id ; }
Salva um registro no banco de dados .
30,905
public function remove ( $ id ) { try { if ( $ this -> softDelete ) { $ removed = [ ] ; $ removed [ $ this -> primaryKey ] = $ id ; $ removed [ $ this -> softDeleteName ] = date ( 'Y-m-d H:i:s' ) ; $ this -> save ( $ removed ) ; } else { $ this -> db -> delete ( $ this -> table , array ( $ this -> primaryKey => $ id ) ) ; } return true ; } catch ( \ Exception $ e ) { return false ; } }
Exclui um registro da tabela .
30,906
protected function insert ( $ data ) { try { if ( $ this -> creationTouch ) { $ data [ $ this -> creationTouchName ] = date ( 'Y-m-d H:i:s' ) ; } $ this -> db -> insert ( $ this -> table , $ this -> fromArray ( $ data ) ) ; $ id = $ this -> db -> lastInsertId ( $ this -> sequence ? $ this -> sequence : $ this -> primaryKey ) ; } catch ( \ Exception $ e ) { throw $ e ; } return $ id ; }
Insere um novo registro na tabela .
30,907
protected function update ( $ data ) { try { if ( $ this -> updateTouch ) { $ data [ $ this -> updateTouchName ] = date ( 'Y-m-d H:i:s' ) ; } $ this -> db -> update ( $ this -> table , $ this -> fromArray ( $ data ) , [ $ this -> primaryKey => $ data [ $ this -> primaryKey ] ] ) ; $ id = $ data [ $ this -> primaryKey ] ; } catch ( \ Exception $ e ) { throw $ e ; } return $ id ; }
Atualiza um registro na tabela .
30,908
protected function paginate ( $ qb , $ pageOpts , $ filters = array ( ) ) { $ db = $ this -> db ; $ total = count ( $ db -> fetchAll ( $ qb -> getSQL ( ) , $ filters ) ) ; if ( isset ( $ pageOpts [ 'start' ] ) ) { $ qb -> setFirstResult ( isset ( $ pageOpts [ 'start' ] ) ? $ pageOpts [ 'start' ] : 0 ) -> setMaxResults ( isset ( $ pageOpts [ 'limit' ] ) ? $ pageOpts [ 'limit' ] : 200 ) ; } $ result = $ db -> fetchAll ( $ qb -> getSQL ( ) , $ filters ) ; return array ( 'total' => $ total , 'results' => $ result ) ; }
Pagina o resultado de uma consulta .
30,909
protected function addFilters ( $ qb , $ filters ) { $ list = [ ] ; $ sgbd = isset ( $ this -> app [ 'dbms' ] ) ? $ this -> app [ 'dbms' ] : 'mysql' ; foreach ( $ filters as $ key => $ filter ) { $ filterKey = str_replace ( '.' , '_' , $ key ) ; if ( is_array ( $ filter ) ) { $ key = $ filter [ 'property' ] ; $ filter = $ filter [ 'clause' ] ; } if ( strpos ( $ key , '.' ) === false ) { $ keyAlias = "t." . $ key ; } else { $ keyAlias = $ key ; $ key = str_replace ( '.' , '_' , $ key ) ; } $ params = explode ( ':' , $ filter ) ; if ( count ( $ params ) == 1 ) { if ( ! in_array ( $ filter , array ( 'isnull' , 'isnotnull' , 'in' , 'notin' ) ) ) { array_unshift ( $ params , '=' ) ; } if ( in_array ( $ filter , array ( 'isnull' , 'isnotnull' ) ) ) { array_unshift ( $ params , $ filter ) ; } } $ filter = $ params [ 1 ] ; switch ( $ params [ 0 ] ) { case '%' : $ list [ $ filterKey ] = "%$filter%" ; if ( $ sgbd == 'postgres' ) { $ qb -> andWhere ( $ keyAlias . ' ilike :' . $ filterKey ) ; } else { $ qb -> andWhere ( $ keyAlias . ' like :' . $ filterKey ) ; } break ; case 'in' : $ qb -> andWhere ( $ keyAlias . ' IN (' . $ filter . ')' ) ; break ; case 'notin' : $ qb -> andWhere ( $ keyAlias . ' NOT IN (' . $ filter . ')' ) ; break ; case 'isnull' : $ qb -> andWhere ( $ keyAlias . ' IS NULL' ) ; break ; case 'isnotnull' : $ qb -> andWhere ( $ keyAlias . ' IS NOT NULL' ) ; break ; default : $ list [ $ filterKey ] = $ filter ; $ qb -> andWhere ( $ keyAlias . ' ' . $ params [ 0 ] . ' :' . $ filterKey ) ; break ; } } return $ list ; }
Adiciona os filtros ao query builder .
30,910
protected function fromArray ( $ source ) { $ data = array ( ) ; $ columnNames = $ this -> getColumnNames ( ) ; foreach ( $ source as $ key => $ value ) { if ( in_array ( $ key , $ columnNames ) ) { if ( is_string ( $ value ) ) { $ value = ( $ value ) ; } $ data [ $ key ] = $ value ; } } return $ data ; }
Mapeia os dados recebidos de um array nos campos existentes na tabela .
30,911
protected function getColumnNames ( ) { $ names = array ( ) ; $ columns = $ this -> db -> getSchemaManager ( ) -> listTableColumns ( $ this -> table ) ; if ( count ( $ columns ) == 0 ) { $ schema = $ this -> schema ? : $ this -> app [ 'db.schema' ] ; $ fullTable = $ schema . "." . $ this -> table ; $ columns = $ this -> db -> getSchemaManager ( ) -> listTableColumns ( $ fullTable ) ; } foreach ( $ columns as $ column ) { $ names [ ] = $ column -> getName ( ) ; } return $ names ; }
Retorna os nomes das colunas da tabela .
30,912
protected function getNamespacedProfile ( $ profile ) { $ parts = explode ( '.' , $ profile ) ; if ( count ( $ parts ) < 2 ) { return [ 'namespace' => false , 'profile' => $ profile ] ; } return [ 'namespace' => $ parts [ 0 ] , 'profile' => $ parts [ 1 ] ] ; }
Recupera um array com o namespace e nome do perfil .
30,913
public function subset ( array $ keys ) { $ subset = clone $ this ; $ items = $ subset -> getItems ( ) ; $ entries = array_intersect_key ( $ subset -> getItems ( ) -> getArrayCopy ( ) , array_flip ( array_values ( $ keys ) ) ) ; $ items -> exchangeArray ( $ entries ) ; return $ subset ; }
Get a subset of the collection .
30,914
public function reduce ( array $ keys ) : self { $ entries = array_intersect_key ( $ this -> getItems ( ) -> getArrayCopy ( ) , array_flip ( array_values ( $ keys ) ) ) ; $ this -> getItems ( ) -> exchangeArray ( $ entries ) ; return $ this ; }
Reduce the collection to only provided keys .
30,915
public function filter ( callable $ callback ) : self { $ entries = array_filter ( $ this -> getItems ( ) -> getArrayCopy ( ) , $ callback ) ; $ this -> getItems ( ) -> exchangeArray ( $ entries ) ; return $ this ; }
Filter this collection based on callback logic .
30,916
public function toFile ( array $ array , string $ filename , int $ flags = 0 ) : bool { $ dir = \ dirname ( $ filename ) ; ! \ is_dir ( $ dir ) && \ mkdir ( $ dir , 0777 , true ) ; return ( bool ) \ file_put_contents ( $ filename , $ this -> dump ( $ array ) , $ flags ) ; }
Dump and output to an external file .
30,917
public function loadObject ( ) { $ serializedObject = $ this -> loadSerializedObject ( ) ; $ object = unserialize ( $ serializedObject ) ; if ( $ object === false ) { return false ; } return $ object ; }
Loads an object
30,918
public static function on ( $ class , $ name , $ handler , $ data = null , $ append = true ) { $ class = Ioc :: resolveClassName ( $ class ) ; if ( $ append || empty ( self :: $ _events [ $ name ] [ $ class ] ) ) { self :: $ _events [ $ name ] [ $ class ] [ ] = [ $ handler , $ data ] ; } else { array_unshift ( self :: $ _events [ $ name ] [ $ class ] , [ $ handler , $ data ] ) ; } }
bind a class - level event .
30,919
public static function has ( $ class , $ name ) { if ( empty ( self :: $ _events [ $ name ] ) ) { return false ; } $ class = Ioc :: resolveClassName ( $ class ) ; do { if ( ! empty ( self :: $ _events [ $ name ] [ $ class ] ) ) { return true ; } } while ( ( $ class = get_parent_class ( $ class ) ) !== false ) ; return false ; }
object or className has the named event
30,920
static public function setEventListener ( $ class , $ listener ) { self :: $ _eventListeners [ Ioc :: resolveClassName ( $ class ) ] [ Ioc :: resolveClassName ( $ listener ) ] = $ listener ; }
set eventListener on some class
30,921
protected function _getTranslator ( string $ lang , string $ suffix = '.yml' , string $ prefix = '' ) : Translator { $ name = $ prefix . $ lang . $ suffix ; return Translator :: fromConfig ( ( array ) $ this -> configLoader -> load ( $ name ) , $ lang ) ; }
Makes Translator from config
30,922
public function render ( array $ ini ) { $ output = [ ] ; foreach ( $ ini as $ sectionName => $ section ) { $ sectionOutput = [ ] ; if ( ! is_array ( $ section ) ) { throw new RendererException ( 'The section must contain an array of key-value pairs' ) ; } $ sectionIni = [ ] ; foreach ( $ section as $ key => $ value ) { if ( is_numeric ( $ key ) ) { if ( ! is_array ( $ value ) ) { $ value = [ $ value ] ; } $ sectionIni = array_merge ( $ sectionIni , $ value ) ; continue ; } $ sectionOutput = array_merge ( $ sectionOutput , $ this -> renderKeyValuePair ( $ key , $ value ) ) ; } if ( count ( $ sectionIni ) > 0 ) { $ sectionOutput = array_merge ( $ this -> renderKeyValuePair ( $ sectionName , $ sectionIni ) , $ sectionOutput ) ; } array_unshift ( $ sectionOutput , sprintf ( '[%s]' , $ sectionName ) ) ; $ sectionOutput [ ] = '' ; $ output = array_merge ( $ output , $ sectionOutput ) ; } return implode ( "\n" , $ output ) ; }
Renders an INI configuration .
30,923
protected function renderKeyValuePair ( $ key , $ value ) { $ output = [ ] ; $ value = $ this -> normalizeValue ( $ value ) ; if ( is_array ( $ value ) ) { foreach ( $ value as $ v ) { $ output [ ] = sprintf ( '%s[] = %s' , $ key , $ v ) ; } } else { $ output [ ] = sprintf ( '%s = %s' , $ key , $ value ) ; } return $ output ; }
Renders a key - value pair .
30,924
protected function normalizeValue ( $ value ) { if ( is_array ( $ value ) ) { $ value = $ this -> normalizeArray ( $ value ) ; } elseif ( is_bool ( $ value ) ) { $ value = $ this -> normalizeBoolean ( $ value ) ; } elseif ( is_null ( $ value ) ) { $ value = 'null' ; } elseif ( is_string ( $ value ) && $ this -> checkFlag ( self :: STRING_MODE_QUOTE ) ) { $ value = sprintf ( '"%s"' , $ value ) ; } return $ value ; }
Normalize value to valid INI format .
30,925
protected function normalizeArray ( $ value ) { switch ( true ) { case $ this -> checkFlag ( self :: ARRAY_MODE_ARRAY ) : default : foreach ( $ value as & $ v ) { if ( is_array ( $ v ) ) { throw new RendererException ( 'Multi-dimensional arrays are not supported by this array mode' ) ; } $ v = $ this -> normalizeValue ( $ v ) ; } return $ value ; break ; case $ this -> checkFlag ( self :: ARRAY_MODE_CONCAT ) : foreach ( $ value as & $ v ) { $ v = trim ( $ this -> normalizeValue ( $ v ) , '"' ) ; } return $ this -> normalizeValue ( implode ( ',' , $ value ) ) ; break ; } }
Normalizes arrays .
30,926
protected function normalizeBoolean ( $ value ) { switch ( true ) { case $ this -> checkFlag ( self :: BOOLEAN_MODE_INTEGER ) : default : return ( int ) $ value ; break ; case $ this -> checkFlag ( self :: BOOLEAN_MODE_BOOL_STRING ) : return $ value === true ? 'true' : 'false' ; break ; case $ this -> checkFlag ( self :: BOOLEAN_MODE_STRING ) : return $ value === true ? 'On' : 'Off' ; break ; } }
Normalizes a boolean value .
30,927
public function setDataContent ( $ content ) { if ( is_array ( $ content ) ) { $ this -> headers -> set ( 'Content-Type' , 'application/json' ) ; $ content = json_encode ( $ content ) ; } $ this -> setContent ( $ content ) ; }
if content is an array then convert to json
30,928
protected function buildCliRequest ( ) { global $ argv ; $ args = $ argv ; $ params = array ( ) ; $ route = '' ; foreach ( $ args as $ arg ) { if ( $ arg === $ _SERVER [ 'PHP_SELF' ] ) { continue ; } if ( strpos ( $ arg , '-' ) === 0 ) { list ( $ key , $ value ) = $ this -> parseArgument ( $ arg ) ; $ params [ $ key ] = $ value ; } else { if ( $ route !== '' ) { $ route .= ' ' ; } $ route .= $ arg ; } } $ base = $ argv [ 0 ] ; $ operatingSystem = $ this -> getOperatingSystem ( ) ; return new CliRequest ( $ route , $ params , $ base , 'en_US' , $ operatingSystem ) ; }
Builds the cli request object
30,929
protected function parseArgument ( $ arg ) { $ arg = ltrim ( $ arg , '-' ) ; $ key = $ arg ; $ value = true ; if ( strpos ( $ arg , '=' ) !== false ) { $ key = substr ( $ arg , 0 , strpos ( $ arg , '=' ) ) ; $ value = substr ( $ arg , strpos ( $ arg , '=' ) + 1 ) ; if ( is_numeric ( $ value ) ) { $ value = $ value * 1 ; } } return array ( $ key , $ value ) ; }
Parses an argument and returns an array with key and value .
30,930
protected function buildWebRequest ( ) { $ args = $ _REQUEST ; $ params = array ( ) ; $ route = $ _SERVER [ 'REQUEST_URI' ] ; $ posQuestionMark = strpos ( $ route , '?' ) ; if ( $ posQuestionMark !== false ) { $ route = substr ( $ route , 0 , $ posQuestionMark ) ; } $ posIndex = strpos ( $ route , 'index.php' ) ; if ( $ posIndex !== false ) { $ route = substr ( $ route , $ posIndex + strlen ( 'index.php' ) ) ; } foreach ( $ args as $ key => $ value ) { if ( is_numeric ( $ value ) ) { $ value = $ value * 1 ; } $ params [ $ key ] = $ value ; } $ scheme = $ this -> getScheme ( ) ; $ fullUrl = $ scheme . '://' . $ _SERVER [ 'HTTP_HOST' ] . $ _SERVER [ 'REQUEST_URI' ] ; $ isSsl = false ; if ( $ scheme == 'https' ) { $ isSsl = true ; } $ routePosition = strlen ( $ fullUrl ) ; if ( $ route !== '' && $ route !== '/' ) { $ routePosition = strpos ( $ fullUrl , $ route ) ; } $ method = $ _SERVER [ 'REQUEST_METHOD' ] ; $ requestedUrl = $ this -> getRequestedUrl ( ) ; $ base = substr ( $ fullUrl , 0 , $ routePosition ) ; $ headers = $ this -> getHeaders ( $ _SERVER ) ; $ protocol = $ _SERVER [ 'SERVER_PROTOCOL' ] ; $ locale = 'en_US' ; if ( isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { $ locale = $ this -> getLocale ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ; } $ operatingSystem = $ this -> getOperatingSystem ( ) ; return new WebRequest ( $ method , $ requestedUrl , $ route , $ params , $ base , $ locale , $ operatingSystem , $ isSsl , $ headers , $ protocol ) ; }
Builds the html request object
30,931
protected function getOperatingSystem ( ) { $ osRaw = strtolower ( PHP_OS ) ; if ( strpos ( $ osRaw , 'linux' ) !== false ) { return RequestAbstract :: OS_LINUX ; } else if ( strpos ( $ osRaw , 'windows' ) !== false ) { return RequestAbstract :: OS_WINDOWS ; } else { return RequestAbstract :: OS_UNKNOWN ; } }
Returns the name of the operating system
30,932
protected function getScheme ( ) { if ( isset ( $ _SERVER [ 'REQUEST_SCHEME' ] ) ) { $ scheme = $ _SERVER [ 'REQUEST_SCHEME' ] ; } else if ( isset ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] ) { $ scheme = 'https' ; } else { if ( $ _SERVER [ 'SERVER_PORT' ] == 443 ) { $ scheme = 'https' ; } else { $ scheme = 'http' ; } } return $ scheme ; }
Returns the scheme of the request
30,933
protected function getHeaders ( $ params ) { $ headers = array ( ) ; foreach ( $ params as $ name => $ value ) { if ( substr ( $ name , 0 , 5 ) === 'HTTP_' ) { $ key = str_replace ( ' ' , '-' , ucwords ( strtolower ( str_replace ( '_' , ' ' , substr ( $ name , 5 ) ) ) ) ) ; $ headers [ $ key ] = $ value ; } } return $ headers ; }
Returns an array with all headers of this request
30,934
protected function getLocale ( $ acceptLanguageHeader ) { $ acceptLanguageHeader = str_replace ( '-' , '_' , $ acceptLanguageHeader ) ; $ locales = explode ( ',' , $ acceptLanguageHeader ) ; $ acceptableLocales = array ( ) ; foreach ( $ locales as $ locale ) { $ priority = 1 ; if ( strpos ( $ locale , ';' ) !== false ) { $ priority = floatval ( substr ( $ locale , strpos ( $ locale , ';' ) ) ) ; $ locale = substr ( $ locale , 0 , strpos ( $ locale , ';' ) ) ; } $ acceptableLocales [ $ priority ] = $ locale ; } krsort ( $ acceptableLocales ) ; $ locale = array_shift ( $ acceptableLocales ) ; if ( $ locale == '' ) { $ locale = 'en_US' ; } else if ( strpos ( $ locale , '_' ) === false ) { $ locale = $ locale . '_' . strtoupper ( $ locale ) ; } return $ locale ; }
Returns the best acceptable locale from the language header .
30,935
public static function extract ( \ DOMElement $ element ) { $ doc = new \ DOMDocument ( '1.0' , 'utf-8' ) ; $ imported = $ doc -> importNode ( $ element , true ) ; $ doc -> appendChild ( $ imported ) ; $ prefix = $ doc -> lookupPrefix ( 'http://www.w3.org/1999/xhtml' ) ; if ( '' !== $ prefix ) { $ prefix .= ':' ; } $ patterns = [ '/<\?xml[^<]*>[^<]*<' . $ prefix . 'div[^<]*/' , '/<\/' . $ prefix . 'div>\s*$/' ] ; $ text = preg_replace ( $ patterns , '' , $ doc -> saveXML ( ) ) ; if ( '' !== $ prefix ) { $ text = preg_replace ( '/(<[\/]?)' . $ prefix . '([a-zA-Z]+)/' , '$1$2' , $ text ) ; } return $ text ; }
Extract HTML from XHTML container .
30,936
public function create ( $ address ) { if ( is_array ( $ address ) ) { $ address = new OrderAddress ( $ address ) ; } if ( $ address instanceof OrderAddress ) { if ( $ this -> fireEvent ( 'creating' , array ( $ address ) ) === false ) { return false ; } $ address -> setCaller ( $ this ) ; $ address -> save ( ) ; $ this -> fireEvent ( 'created' , array ( $ address ) ) ; $ address = $ this -> find ( $ address -> id ) ; return $ address ; } throw new Exception ( sprintf ( Exception :: CANT_CREATE_MODEL , 'Subbly\\Model\\Order' , $ this -> name ( ) ) ) ; }
Create a new OrderAdress .
30,937
public function getTrips ( ) { $ trips = $ this -> trips ; usort ( $ trips , function ( Trip $ a , Trip $ b ) { return $ a -> compareWith ( $ b ) ; } ) ; return new \ ArrayIterator ( $ trips ) ; }
List of trips ordered by departure time
30,938
public function setTableName ( $ tableName ) { $ this -> query = str_replace ( $ this -> tableName , $ tableName , $ this -> query ) ; $ this -> dummyQuery = str_replace ( $ this -> tableName , $ tableName , $ this -> dummyQuery ) ; $ this -> tableName = $ tableName ; return $ this ; }
Set the name of the table for which the query criteria is for
30,939
public function endGroup ( ) { if ( $ this -> groups ) { $ this -> query .= ')' ; $ this -> dummyQuery .= ')' ; $ this -> groups -- ; } return $ this ; }
End criteria grouping
30,940
public static function escape ( array $ args ) : string { $ command = '' ; foreach ( $ args as $ arg ) { if ( $ command != '' ) $ command .= ' ' ; $ command .= escapeshellarg ( $ arg ) ; } return $ command ; }
Returns a popper escaped command .
30,941
public function transform ( MemberTag $ memberTag ) { return [ 'createdAt' => $ memberTag -> created_at -> toW3cString ( ) , 'description' => $ memberTag -> description , 'id' => $ memberTag -> id , 'name' => $ memberTag -> name , ] ; }
Transformer to generate JSON response with MemberTag
30,942
public function getNewValue ( int $ maxValue , int $ changeValue , string $ progressType ) { switch ( $ progressType ) { case AchievementCriteriaChange :: PROGRESS_SET : $ newValue = $ changeValue ; break ; case AchievementCriteriaChange :: PROGRESS_ACCUMULATE : $ newValue = $ this -> value + $ changeValue ; if ( $ maxValue > 0 ) { $ newValue = $ maxValue - $ this -> value > $ changeValue ? $ this -> value + $ changeValue : $ maxValue ; } break ; case AchievementCriteriaChange :: PROGRESS_HIGHEST : $ newValue = $ this -> value < $ changeValue ? $ changeValue : $ this -> value ; break ; default : throw new \ InvalidArgumentException ( 'Given progress type is invalid (' . $ progressType . ').' ) ; } return $ newValue ; }
Calculates new progress value .
30,943
public function viewData ( $ key = null , $ value = null ) { $ view = $ this -> getView ( ) ; if ( ! $ key ) { return $ view -> getData ( ) ; } elseif ( is_null ( $ value ) && is_string ( $ key ) ) { $ viewData = $ view -> getData ( ) ; return isset ( $ viewData [ $ key ] ) ? $ viewData [ $ key ] : null ; } else { $ view -> setData ( $ key , $ value ) ; return $ this ; } }
get or set view data
30,944
public function renderXml ( $ data = null ) { $ this -> beforeRender ( $ data ) ; $ this -> response = $ this -> response -> withHeader ( 'Content-Type' , 'application/xml;charset=utf-8' ) ; $ string = XmlFormatter :: encode ( $ this -> responseData ( ) -> all ( ) ) ; return static :: renderText ( $ string ) ; }
render xml from template
30,945
public function renderHtml ( $ template = null , $ data = null ) { $ this -> beforeRender ( $ data ) ; $ this -> beforeRenderView ( ) ; $ template = ! empty ( $ template ) ? $ template : $ this -> getName ( ) ; $ string = $ this -> module -> getView ( ) -> render ( $ template , $ this -> responseData ( ) ) ; return $ this -> renderText ( $ string ) ; }
render html from template
30,946
final public function forward ( $ path , $ query = null ) { $ this -> stop ( ) ; $ parts = parse_url ( $ path ) ; $ path = $ parts [ 'path' ] ; $ pathQuery = isset ( $ parts [ 'query' ] ) ? $ parts [ 'query' ] : null ; if ( strpos ( $ path , '/' ) === 0 ) { $ controller = Ioc :: web ( ) -> getController ( $ path ) ; } else { $ controller = $ this -> getModule ( ) -> getController ( $ path ) ; } if ( ! $ controller ) { $ this -> request = $ this -> request -> withUri ( Uri :: createFromString ( $ path ) ) ; return $ this -> notFound ( ) ; } if ( $ pathQuery && is_string ( $ pathQuery ) ) { parse_str ( $ pathQuery , $ pathQuery ) ; } if ( $ query && is_string ( $ query ) ) { parse_str ( $ query , $ query ) ; } $ query = array_merge ( ( array ) $ pathQuery , ( array ) $ query ) ; if ( $ query ) { $ this -> request = $ this -> request -> withQueryParams ( $ pathQuery ) ; } return $ controller -> handle ( $ this -> request , $ this -> response ) ; }
forward the uri
30,947
protected function getBillingPlanFilterByName ( $ value ) { $ billingPlans = $ this -> getBillingPlans ( ) ; foreach ( $ billingPlans as $ billingPlan ) { if ( $ billingPlan -> name === $ value ) { return $ billingPlan ; } } return null ; }
Get a plan filter by name .
30,948
public function addPlugin ( PluginInterface $ plugin ) { $ plugin -> setNode ( $ this ) ; $ this -> plugins -> attach ( $ plugin ) ; }
Attach a plugin
30,949
public function getPlugin ( $ slug ) { $ this -> plugins -> rewind ( ) ; while ( $ this -> plugins -> valid ( ) ) { if ( $ this -> plugins -> current ( ) -> getSlug ( ) == $ slug ) { return $ this -> plugins -> current ( ) ; } $ this -> plugins -> next ( ) ; } return false ; }
Get a plugin by slug or return false when none can be found
30,950
static public function decodeElement ( $ str , $ hasRoot = true ) { if ( is_array ( $ str ) ) { return $ str ; } if ( ! $ hasRoot && strpos ( $ str , '<?xml' ) !== 0 && strpos ( $ str , '<xml' ) !== 0 ) { $ str = "<?xml version='1.0' encoding='utf-8'?><xml>" . $ str . "</xml>" ; } libxml_disable_entity_loader ( true ) ; return json_decode ( json_encode ( simplexml_load_string ( $ str , 'SimpleXMLElement' , LIBXML_NOCDATA ) ) , true ) ; }
from xml string to array use single entity parse
30,951
static public function append ( $ root , $ data , $ options = [ ] ) { $ rootString = static :: root ( $ root ) ; $ rootNode = simplexml_load_string ( $ rootString ) ; return static :: addDataToNode ( $ rootNode , $ data ) -> asXML ( ) ; }
append data to rootString
30,952
static public function root ( $ data = null ) { if ( ! $ data ) { $ data = static :: encodeElement ( [ ] , 'xml' ) ; } elseif ( is_array ( $ data ) ) { $ data = static :: encodeElement ( $ data , null ) ; } elseif ( strpos ( $ data , '<' ) === false ) { $ data = static :: encodeElement ( "<$data></$data>" , null ) ; } $ node = simplexml_load_string ( $ data ) ; return $ node -> asXML ( ) ; }
return root string
30,953
static public function toXml ( $ data ) { if ( is_array ( $ data ) ) { $ data = static :: encode ( $ data ) ; } return simplexml_load_string ( $ str , 'SimpleXMLElement' , LIBXML_NOCDATA ) ; }
from string to SimpleXMLElement
30,954
public function send ( $ name , $ parameters = [ ] , $ locale = null , \ Closure $ messageModifier = null ) { $ mailDefinition = $ this -> provider -> fetchMailDefinition ( $ name , $ parameters ) ; $ parsedMessage = $ this -> parser -> parseMailDefinition ( $ mailDefinition , $ locale ? : $ this -> locale ) ; $ this -> handleDefaults ( $ parsedMessage ) ; $ this -> mailer -> send ( $ parsedMessage , $ messageModifier ) ; }
Sends out the system message
30,955
protected function handleDefaults ( ParsedMessage $ parsedMessage ) { if ( ! $ parsedMessage -> getFrom ( ) && $ this -> defaults [ 'from' ] [ 'email' ] ) { $ parsedMessage -> setFrom ( $ this -> defaults [ 'from' ] [ 'email' ] , $ this -> defaults [ 'from' ] [ 'name' ] ) ; } if ( ! $ parsedMessage -> getTo ( ) && $ this -> defaults [ 'to' ] [ 'email' ] ) { $ parsedMessage -> addTo ( $ this -> defaults [ 'to' ] [ 'email' ] , $ this -> defaults [ 'to' ] [ 'name' ] ) ; } if ( ! $ parsedMessage -> getCc ( ) && $ this -> defaults [ 'cc' ] [ 'email' ] ) { $ parsedMessage -> addCC ( $ this -> defaults [ 'cc' ] [ 'email' ] , $ this -> defaults [ 'cc' ] [ 'name' ] ) ; } if ( ! $ parsedMessage -> getBcc ( ) && $ this -> defaults [ 'bcc' ] [ 'email' ] ) { $ parsedMessage -> addBcc ( $ this -> defaults [ 'bcc' ] [ 'email' ] , $ this -> defaults [ 'bcc' ] [ 'name' ] ) ; } if ( ! $ parsedMessage -> getReplyTo ( ) && $ this -> defaults [ 'replyTo' ] ) { $ parsedMessage -> setReplyTo ( $ this -> defaults [ 'replyTo' ] ) ; } if ( ! $ parsedMessage -> getSubject ( ) && $ this -> defaults [ 'subject' ] ) { $ parsedMessage -> setSubject ( $ this -> defaults [ 'subject' ] ) ; } }
Add default parameters when they are not provided from the MailDefinition
30,956
public function checkSyntax ( $ json ) { $ parser = new JsonParser ; if ( ( $ result = $ parser -> lint ( $ json ) ) instanceof ParsingException ) { throw $ result ; } }
Checks the syntax of the JSON string .
30,957
public function parse ( $ json , $ assoc = false , $ depth = 512 ) { if ( null === ( $ data = json_decode ( $ json , $ assoc , $ depth ) ) ) { if ( JSON_ERROR_UTF8 === json_last_error ( ) ) { throw JsonException :: invalidUtf8 ( ) ; } $ this -> checkSyntax ( $ json ) ; } return $ data ; }
Parses a JSON string .
30,958
public function parseFile ( $ file , $ assoc = false , $ depth = 512 ) { if ( false === is_file ( $ file ) ) { throw new InvalidArgumentException ( sprintf ( 'The JSON file path "%s" is either not a file or it does not exist.' , $ file ) ) ; } if ( false === ( $ contents = @ file_get_contents ( $ file ) ) ) { $ error = error_get_last ( ) ; throw new RuntimeException ( sprintf ( 'The JSON file "%s" could not be read: %s' , $ file , $ error [ 'message' ] ) ) ; } return $ this -> parse ( $ contents , $ assoc , $ depth ) ; }
Parses a JSON file .
30,959
public function validate ( $ schema , $ json ) { $ validator = new Validator ; $ validator -> check ( $ json , $ schema ) ; if ( false === $ validator -> isValid ( ) ) { $ errors = array ( ) ; foreach ( $ validator -> getErrors ( ) as $ error ) { $ errors [ ] = ( empty ( $ error [ 'property' ] ) ? '' : $ error [ 'property' ] . ': ' ) . $ error [ 'message' ] ; } throw JSONException :: errors ( $ errors ) ; } }
Validates the JSON data .
30,960
public function addMethod ( Method $ method ) : void { if ( ! $ this -> responses -> has ( $ method -> getResponse ( ) ) && $ this -> structures -> has ( $ method -> getResponse ( ) ) ) { $ struct = $ this -> structures -> get ( $ method -> getResponse ( ) ) ; $ response = Response :: createFromStruct ( $ struct ) ; $ this -> responses -> add ( $ response ) ; $ this -> structures -> remove ( $ struct ) ; } if ( ! $ this -> requests -> has ( $ method -> getRequest ( ) ) && $ this -> structures -> has ( $ method -> getRequest ( ) ) ) { $ struct = $ this -> structures -> get ( $ method -> getRequest ( ) ) ; $ request = Request :: createFromStruct ( $ struct ) ; $ this -> requests -> add ( $ request ) ; $ this -> structures -> remove ( $ struct ) ; } $ this -> methods -> add ( $ method ) ; }
Add a named method .
30,961
public function notify ( ) { foreach ( $ this -> observer as $ observer ) { $ this -> storeData ( $ observer -> getIdentifier ( ) , $ observer -> update ( $ this ) ) ; } return $ this -> getStore ( self :: IDENTIFIER_VIEW ) ; }
Notifies all registered observers about an update
30,962
public function getStoredData ( $ source = null ) { if ( null === $ source ) { $ result = $ this -> store ; } else { if ( false === isset ( $ this -> store [ $ source ] ) ) { throw new Doozr_Base_Presenter_Exception ( sprintf ( 'No stored data for source (key) "%s"' , $ source ) ) ; } $ result = $ this -> store [ $ source ] ; } return $ result ; }
Returns the data from internal store .
30,963
protected function render ( $ filePath , $ variables = array ( ) ) { foreach ( $ this -> _vars as $ k => $ n ) { $ $ k = $ n ; } foreach ( $ variables as $ k => $ n ) { $ $ k = $ n ; } require $ filePath ; }
Display a template using full path . It will also assign all variables to it .
30,964
public function findBillingAgreements ( PricingContextInterface $ context , $ limit = null , $ page = 1 ) { $ offset = ( $ page - 1 ) * $ limit ; if ( isset ( $ context [ 'endDate' ] ) ) { $ endDate = new \ DateTime ( $ context [ 'endDate' ] ) ; } else { $ endDate = new \ DateTime ( ) ; } $ params = array ( 1 => $ endDate ) ; $ query = $ this -> gateway -> createQuery ( 'select' , $ this -> billingAgreementClass ) ; $ qb = $ query -> getQueryBuilder ( ) ; $ qb -> join ( 'm.paymentProfile' , 'pp' ) ; $ qb -> andWhere ( 'm.generateRequestOn <= ?1' ) ; if ( isset ( $ context [ 'partner' ] ) ) { $ qb -> andWhere ( 'm.partner = ?3' ) ; $ params [ 3 ] = $ context [ 'partner' ] ; } $ qb -> andWhere ( 'm.active = ?4' ) ; $ params [ 4 ] = 1 ; if ( $ limit ) { $ qb -> setMaxResults ( $ limit ) -> setFirstResult ( $ offset ) ; } return $ qb -> setParameters ( $ params ) -> getQuery ( ) -> getResult ( ) ; }
Finds billing agreements that are due
30,965
public function initLocaleNamespace ( $ locale , array $ namespaces ) { $ checksum = hash ( 'md4' , $ locale . serialize ( $ namespaces ) ) ; $ translationTable = false ; if ( true === $ this -> hasTranslationTableSupport ( $ this ) ) { if ( false === isset ( self :: $ translationTables [ $ checksum ] ) || false === $ this -> getCacheEnabled ( ) ) { if ( true === $ this -> getCacheEnabled ( ) ) { try { $ translationTable = self :: $ cache -> read ( $ checksum ) ; } catch ( Doozr_Cache_Service_Exception $ e ) { } } if ( false === $ translationTable ) { $ translationTable = $ this -> buildTranslationtable ( $ locale , $ namespaces ) ; } if ( true === $ this -> getCacheEnabled ( ) ) { self :: $ cache -> create ( $ checksum , $ translationTable , $ this -> getCacheLifetime ( ) ) ; } self :: $ translationTables [ $ checksum ] = $ translationTable ; } } return $ checksum ; }
Starts the initializing of given locale and namespace .
30,966
protected function removeTranslationTable ( $ key ) { if ( true === isset ( self :: $ translationTables [ $ key ] ) ) { unset ( self :: $ translationTables [ $ key ] ) ; } }
Adds a single translationTable to collection of translationTables .
30,967
protected function removeTranslation ( $ key ) { if ( true === isset ( self :: $ translations [ $ key ] ) ) { unset ( self :: $ translations [ $ key ] ) ; } }
Adds a single translation to collection of translations .
30,968
protected function hasTranslationTableSupport ( Doozr_I18n_Service_Interface_Interface $ instance ) { $ method = 'buildTranslationtable' ; return method_exists ( $ instance , $ method ) && is_callable ( [ $ instance , $ method ] ) ; }
Returns either the interface has a translation table support or not .
30,969
private static function getFlippedTimezones ( ) { if ( null === static :: $ timezones ) { static :: $ timezones = [ ] ; foreach ( \ DateTimeZone :: listIdentifiers ( ) as $ timezone ) { $ parts = explode ( '/' , $ timezone ) ; if ( \ count ( $ parts ) > 2 ) { $ region = $ parts [ 0 ] ; } elseif ( \ count ( $ parts ) > 1 ) { $ region = $ parts [ 0 ] ; } else { $ region = 'Other' ; } static :: $ timezones [ $ region ] [ str_replace ( '_' , ' ' , $ timezone ) ] = $ timezone ; } } return static :: $ timezones ; }
Returns the timezone choices .
30,970
public function execute ( ) { $ pdoStatement = $ this -> pdo -> prepare ( ( string ) $ this ) ; foreach ( $ this -> bindings as $ clause => $ predicate ) { foreach ( $ predicate as $ key => $ value ) { $ pdoStatement -> bindValue ( sprintf ( ':%s%d' , $ clause , $ key + 1 ) , $ value , $ this -> getPdoDataType ( $ value ) ) ; } } $ pdoStatement -> execute ( ) ; return new QueryResult ( $ pdoStatement ) ; }
Returns the result of the executed prepared query .
30,971
private function getPdoDataType ( $ value ) { $ result = \ PDO :: PARAM_STR ; if ( is_bool ( $ value ) ) { $ result = \ PDO :: PARAM_BOOL ; } elseif ( is_null ( $ value ) ) { $ result = \ PDO :: PARAM_NULL ; } elseif ( is_int ( $ value ) ) { $ result = \ PDO :: PARAM_INT ; } return $ result ; }
Returns the data type of the given value .
30,972
private function addBinding ( $ clause , $ value ) { $ this -> bindings [ $ clause ] [ ] = $ value ; return sprintf ( ':%s%d' , $ clause , count ( $ this -> bindings [ $ clause ] ) ) ; }
Returns a binding for the given clause and value .
30,973
private function addBindings ( $ clause , array $ values ) { $ result = [ ] ; foreach ( $ values as $ key => $ value ) { $ result [ $ key ] = $ this -> addBinding ( $ clause , $ value ) ; } return $ result ; }
Returns bindings for the given clause and values .
30,974
public function hiddenInput ( $ name , $ value = null , $ htmlOptions = array ( ) ) { return $ this -> input ( $ name , 'hidden' , $ value , $ htmlOptions ) ; }
Generates a hidden input field with the specified name value and htmlOptions .
30,975
public function openForm ( $ htmlOptions ) { $ r = '<form ' ; foreach ( $ htmlOptions as $ k => $ v ) $ r .= "$k = '$v' " ; return $ r . '>' . ( ( isset ( $ htmlOptions [ 'method' ] ) && 'post' == strtolower ( $ htmlOptions [ 'method' ] ) ) ? $ this -> hiddenInput ( WebApp :: get ( ) -> request ( ) -> getCsrfKey ( ) , WebApp :: get ( ) -> request ( ) -> getCsrfValue ( ) ) : '' ) ; }
Returns an open form tag with the selected html options ;
30,976
public function htmlTextarea ( $ name , $ value = null , $ htmlOptions = array ( ) , $ tinyMCETemplate = 'basic' ) { $ r = Html :: get ( ) -> mpfScriptFile ( 'jquery.js' ) . Html :: get ( ) -> mpfScriptFile ( 'tinymce/tinymce.min.js' ) . Html :: get ( ) -> mpfScriptFile ( 'tinymce/jquery.tinymce.min.js' ) ; if ( ! isset ( $ htmlOptions [ 'id' ] ) ) { $ htmlOptions [ 'id' ] = 'tinymce_' . uniqid ( ) ; } $ htmlOptions [ 'class' ] = ( isset ( $ htmlOptions [ 'class' ] ) ? $ htmlOptions [ 'class' ] . ' ' : '' ) . 'input tinymce-textarea' ; $ r .= $ this -> textarea ( $ name , $ value , $ htmlOptions ) ; $ options = json_encode ( $ this -> tinyMCEOptionTemplates [ $ tinyMCETemplate ] ) ; $ r .= Html :: get ( ) -> script ( "$('#{$htmlOptions['id']}').tinymce($options)" ) ; return $ r ; }
Generates an HTML Textarea using TinyMCE
30,977
public function checkboxGroup ( $ name , $ options , $ selected = null , $ htmlOptions = [ ] , $ template = '<input><label>' , $ separator = '<br />' ) { if ( is_null ( $ selected ) ) { $ selected = $ this -> getArrayValue ( $ _POST , $ name ) ; if ( is_null ( $ selected ) ) { $ selected = $ this -> getArrayValue ( $ _GET , $ name ) ; } } $ r = array ( ) ; foreach ( $ options as $ value => $ label ) { $ r [ ] = $ this -> checkbox ( $ name . '[]' , $ label , $ value , is_array ( $ selected ) ? in_array ( $ value , $ selected ) : $ selected == $ value , $ htmlOptions , $ template ) ; } return implode ( $ separator , $ r ) ; }
Generate a group of checkbox inputs
30,978
public function date ( $ name , $ value = null , $ format = 'yy-mm-dd' , $ htmlOptions = array ( ) ) { $ return = Html :: get ( ) -> mpfScriptFile ( 'jquery.js' ) . Html :: get ( ) -> mpfScriptFile ( 'jquery-ui/jquery-ui.js' ) ; if ( ! isset ( $ htmlOptions [ 'id' ] ) ) { $ htmlOptions [ 'id' ] = 'mdate-time' . str_replace ( array ( '[' , ']' ) , array ( '_' , '__' ) , $ name ) . $ this -> _date_input_count ; if ( WebApp :: get ( ) -> request ( ) -> isAjaxRequest ( ) ) { $ htmlOptions [ 'id' ] = 'ajax-' . $ htmlOptions [ 'id' ] ; } $ this -> _date_input_count ++ ; } $ s = Html :: get ( ) -> script ( "$(function(){\$(\"#{$htmlOptions['id']}\").datepicker({dateFormat: '$format'});});" ) ; return $ return . $ this -> input ( $ name , 'text' , $ value , $ htmlOptions ) . $ s ; }
Get HTML input with jQuery UI date .
30,979
function setPassword ( $ password ) { $ salt = Pluf_Utils :: getRandomString ( 5 ) ; $ this -> password = 'sha1:' . $ salt . ':' . sha1 ( $ salt . $ password ) ; return true ; }
Set the password of a user .
30,980
function checkPassword ( $ password ) { if ( $ this -> password == '' ) { return false ; } list ( $ algo , $ salt , $ hash ) = explode ( ':' , $ this -> password ) ; if ( $ hash == $ algo ( $ salt . $ password ) ) { return true ; } else { return false ; } }
Check if password is valid
30,981
public static function getCredential ( $ userId ) { $ model = new User_Credential ( ) ; $ where = 'account_id = ' . $ model -> _toDb ( $ userId , 'account_id' ) ; $ creds = $ model -> getList ( array ( 'filter' => $ where ) ) ; if ( $ creds === false or count ( $ creds ) !== 1 ) { return false ; } return $ creds [ 0 ] ; }
Returns credential for given account id
30,982
public static function checkCredential ( $ login , $ password ) { $ account = User_Account :: getUser ( $ login ) ; $ credit = new User_Credential ( ) ; $ credit = $ credit -> getOne ( "account_id=" . $ account -> id ) ; if ( ! $ credit ) { return false ; } return $ credit -> checkPassword ( $ password ) ; }
Check if the login creditential is valid .
30,983
protected function importMapFromFromJsonFile ( $ file ) { $ content = $ this -> validate ( $ this -> readFile ( $ file ) ) ; if ( false === $ content ) { throw new Doozr_Di_Exception ( sprintf ( 'Error while importing dependencies: "%s".' , json_last_error_msg ( ) ) ) ; } if ( false === isset ( $ content [ 'map' ] [ 0 ] ) ) { throw new Doozr_Di_Exception ( sprintf ( 'Require key "%s" not found!' , 'map' ) ) ; } return $ content [ 'map' ] [ 0 ] ; }
Returns the content of a file in JSON - syntax as object .
30,984
protected function validate ( $ input ) { if ( true === is_string ( $ input ) ) { $ input = @ json_decode ( $ input , true ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { $ input = false ; } } return $ input ; }
Validates that a passed string is valid json .
30,985
public function transform ( $ value ) { if ( null === $ value ) { return '' ; } if ( ! is_numeric ( $ value ) ) { throw new TransformationFailedException ( 'Expected a numeric.' ) ; } $ formatter = $ this -> getNumberFormatter ( \ NumberFormatter :: PERCENT ) ; $ value = $ formatter -> format ( $ value ) ; return $ value ; }
Transforms a number type into localized percent .
30,986
private function getTemplatePath ( $ name ) { if ( strpos ( $ name , '::' ) !== false ) { $ parts = explode ( '::' , $ name ) ; $ ns = array_shift ( $ parts ) ; if ( isset ( $ this -> manager -> namespaces [ $ ns ] ) ) { $ path = $ this -> manager -> namespaces [ $ ns ] . '/' . join ( '/' , $ parts ) . $ this -> manager -> filesExtension ; } else { throw new LogicException ( sprintf ( "Template namespace '%s::' not defined" , $ ns ) ) ; } } else { $ path = $ this -> manager -> defaultDirectory . '/' . $ name . $ this -> manager -> filesExtension ; } if ( file_exists ( $ path ) ) { return $ path ; } throw new LogicException ( sprintf ( "Template file '%s' not found" , $ path ) ) ; }
Getting template path by template name .
30,987
public function run ( ) { $ classes = $ this -> generateClass ( ) ; echo Html :: beginTag ( 'div' , [ 'class' => $ classes ] ) . "\n" ; echo $ this -> renderItems ( ) . "\n" ; echo Html :: endTag ( 'div' ) . "\n" ; }
run function .
30,988
private function generateClass ( ) { $ class [ ] = 'icon-bar' ; if ( $ this -> iconsUp === 0 ) { $ class [ ] = $ this -> getCountUp ( count ( $ this -> icons [ 'items' ] ) ) ; } else { $ class [ ] = $ this -> getCountUp ( $ this -> iconsUp ) ; } if ( $ this -> direction != 'horizontal' ) { $ class [ ] = $ this -> direction ; } if ( $ this -> labelRight ) { $ class [ ] = 'label-right' ; } return implode ( " " , $ class ) ; }
generateClass function .
30,989
private function renderItems ( ) { $ items = [ ] ; $ icons = $ this -> icons [ 'items' ] ; foreach ( $ icons as $ i ) { $ labelContent = $ i [ 'label' ] ; if ( $ this -> encodeLabel ) { $ labelContent = Html :: encode ( $ labelContent ) ; } $ label = Html :: tag ( 'label' , $ labelContent ) . "\n" ; $ icon = Html :: tag ( 'i' , '' , [ 'class' => $ i [ 'icon' ] ] ) . "\n" ; $ options = ArrayHelper :: getValue ( $ i , 'options' , [ ] ) ; if ( isset ( $ options [ 'class' ] ) ) { $ addClass = 'item ' . $ options [ 'class' ] ; $ options = [ 'class' => $ addClass , ] ; } else { $ options [ 'class' ] = 'item' ; } $ url = $ i [ 'url' ] ; $ items [ ] = Html :: a ( $ icon . $ label , $ url , $ options ) . "\n" ; } return implode ( "\n" , $ items ) ; }
renderItems function .
30,990
public function withEntry ( string $ key , $ value ) : self { $ this -> bindings [ $ key ] = $ this -> getValueCreator ( $ value ) ; return $ this ; }
adds an entry to the list
30,991
public function withEntryFromProvider ( string $ key , $ provider ) : self { $ this -> bindings [ $ key ] = $ this -> getProviderCreator ( $ provider ) ; return $ this ; }
adds an entry to the map created by an injection provider
30,992
public function withEntryFromClosure ( string $ key , \ Closure $ closure ) : self { $ this -> bindings [ $ key ] = $ closure ; return $ this ; }
adds an entry which is created by given closure
30,993
public function run ( $ args ) { $ args = $ this -> parseArgs ( $ args ) ; if ( ! isset ( $ args [ 0 ] ) || ! $ args [ 0 ] || ! $ this -> isPackageName ( $ args [ 0 ] ) ) { return $ this -> error ( '&require-package' ) ; } if ( ! is_dir ( $ this -> cwd . '/vendor/' . $ args [ 0 ] ) ) { return $ this -> error ( '&package-not-found' ) ; } $ packageName = $ args [ 0 ] ; $ projectName = isset ( $ args [ 1 ] ) ? $ args [ 1 ] : basename ( $ args [ 0 ] ) ; return $ this -> exec ( 'mount' , 'mount' , [ $ packageName , $ projectName ] ) ; }
Run mount command .
30,994
public function getAdapter ( ) { if ( is_null ( $ this -> adapter ) || ! $ this -> adapter instanceof AdapterInterface ) { $ class = '\\Wslim\\Db\Adapter\\' . $ this -> options [ 'adapter' ] . 'Adapter' ; if ( ! class_exists ( $ class ) ) { throw new DbException ( 'database adapter is not exists:' . $ class ) ; } $ this -> adapter = new $ class ( $ this -> options ) ; } return $ this -> adapter ; }
fetch the db adapter instance
30,995
public function getParser ( ) { if ( ! isset ( $ this -> parser ) ) { $ class = '\\Wslim\\Db\\Parser\\' . $ this -> options [ 'adapter' ] . 'QueryParser' ; if ( ! class_exists ( $ class ) ) { throw new DbException ( 'QueryParser is not exists:' . $ class ) ; } $ this -> parser = new $ class ( ) ; } return $ this -> parser ; }
fetch the db QueryParser instance
30,996
public function getSchema ( ) { if ( ! isset ( $ this -> schema ) ) { $ class = '\\Wslim\\Db\\Schema\\' . $ this -> options [ 'adapter' ] . 'Schema' ; if ( class_exists ( $ class ) ) { $ this -> schema = new $ class ( $ this -> getAdapter ( ) ) ; } else { throw new DbException ( 'Schema is not exist:' . $ class ) ; } } return $ this -> schema ; }
get schema instance
30,997
public function getTables ( $ database = null ) { if ( empty ( $ database ) ) $ database = $ this -> getDatabase ( ) ; $ key = 'db/tables/' . $ database ; $ data = static :: getCache ( ) -> get ( $ key ) ; if ( ! $ data ) { $ data = $ this -> getAdapter ( ) -> getTables ( $ database ) ; static :: getCache ( ) -> set ( $ key , $ data ) ; } return $ data ; }
Get an array of the tables of the database .
30,998
public function getTableInfo ( $ table ) { if ( ! $ this -> tableExists ( $ table ) ) { return null ; } $ rtable = static :: buildRealTableName ( $ table , true ) ; $ key = 'db/tableinfo/' . $ rtable ; $ data = static :: getCache ( ) -> get ( $ key ) ; if ( ! $ data ) { $ data = [ 'table_name' => $ table ] ; $ data [ 'fields' ] = $ this -> getColumns ( $ table ) ; $ pk = [ ] ; foreach ( $ data [ 'fields' ] as $ key => $ val ) { if ( $ val [ 'is_primary' ] ) { $ pk [ ] = $ key ; } } $ data [ 'primary_key' ] = $ pk ? $ pk [ 0 ] : null ; static :: getCache ( ) -> set ( $ key , $ data ) ; } return $ data ; }
get table info
30,999
public function getCreateTableSql ( $ table ) { $ table = $ this -> buildRealTableName ( $ table ) ; return $ this -> getSchema ( ) -> getCreateTableSql ( $ table ) ; }
get create table sql